ZQuest Classic Coverage Report


Directory: src/
File: src/zc/zc_sys.cpp
Date: 2025-12-07 03:15:32
Exec Total Coverage
Lines: 2000 4583 43.6%
Functions: 128 335 38.2%
Branches: 1349 3786 35.6%

Line Branch Exec Source
1 #include "zc/zc_sys.h"
2
3 #include "allegro/gfx.h"
4 #include "allegro/gui.h"
5 #include "allegro/inline/draw.inl"
6 #include "allegro5/joystick.h"
7 #include "base/files.h"
8 #include "base/render.h"
9 #include "base/zdefs.h"
10 #include "zalleg/zalleg.h"
11 #include "base/qrs.h"
12 #include "base/dmap.h"
13 #include <functional>
14 #include <queue>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <cstring>
18 #include <math.h>
19 #include <map>
20 #include <filesystem>
21 #include <ctype.h>
22 #include <sstream>
23 #include "base/version.h"
24 #include "base/zc_alleg.h"
25 #include "gamedata.h"
26 #include "zc/frame_timings.h"
27 #include "zc/replay_upload.h"
28 #include "zc/zasm_pipeline.h"
29 #include "zc/zc_init.h"
30 #include "init.h"
31 #include "zc/replay.h"
32 #include "zc/cheats.h"
33 #include "zc/render.h"
34 #include "base/zc_math.h"
35 #include "base/zapp.h"
36 #include "dialog/cheatkeys.h"
37 #include "metadata/metadata.h"
38 #include "zc/zelda.h"
39 #include "zc/saves.h"
40 #include "tiles.h"
41 #include "base/colors.h"
42 #include "pal.h"
43 #include "base/zsys.h"
44 #include "base/qst.h"
45 #include "zc/zc_sys.h"
46 #include "play_midi.h"
47 #include "gui/jwin_a5.h"
48 #include "base/jwinfsel.h"
49 #include "base/gui.h"
50 #include "midi.h"
51 #include "subscr.h"
52 #include "zc/maps.h"
53 #include "sprite.h"
54 #include "zc/guys.h"
55 #include "zc/hero.h"
56 #include "zc/title.h"
57 #include "particles.h"
58 #include "sound/zcmusic.h"
59 #include "zc/ffscript.h"
60 #include "dialog/info.h"
61 #include "dialog/alert.h"
62 #include "zc/combos.h"
63 #include "zc/jit.h"
64 #include "zc/zc_subscr.h"
65 #include <fmt/format.h>
66 #include "zconsole/ConsoleLogger.h"
67 #include "zinfo.h"
68 #include "base/misctypes.h"
69 #include "music_playback.h"
70 #include "base/new_menu.h"
71 #include "base/files.h"
72 #include "iter.h"
73
74 #ifdef __EMSCRIPTEN__
75 #include "base/emscripten_utils.h"
76 #endif
77
78 using namespace std::chrono_literals;
79
80 extern bool Playing;
81 int32_t sfx_voice[WAV_COUNT];
82 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c);
83 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c);
84
85 static ALLEGRO_JOYSTICK* gamepad_dlg_cur_joystick;
86 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c);
87
88 extern byte monochrome_console;
89
90 extern sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations;
91 extern std::string loadlast;
92 extern char *sfx_string[WAV_COUNT];
93 byte use_dwm_flush;
94 byte use_save_indicator;
95 int32_t paused_midi_pos = 0;
96 byte midi_suspended = 0;
97 byte zc_192b163_warp_compatibility;
98 bool epilepsyFlashReduction;
99 signed char pause_in_background_menu_init = 0;
100 byte pause_in_background = 0;
101 bool is_sys_pal = false;
102 static bool load_control_called_this_frame;
103 extern PALETTE* hw_palette;
104 extern bool update_hw_pal;
105 extern const char* dmaplist(int32_t index, int32_t* list_size);
106 int32_t getnumber(const char *prompt,int32_t initialval);
107
108 extern bool kb_typing_mode; //script only, for disbaling key presses affecting Hero, etc.
109 extern int32_t cheat_modifier_keys[4]; //two options each, default either control and either shift
110
111 #ifdef ALLEGRO_LINUX
112 static const char *samplepath = "samplesoundset/patches.dat";
113 #endif
114 char qst_files_path[2048];
115
116 extern TopMenu the_player_menu;
117 #ifdef _MSC_VER
118 #define getcwd _getcwd
119 #endif
120
121 bool rF11();
122 bool rI();
123 bool rQ();
124 bool zc_key_pressed();
125
126 #ifdef _WIN32
127
128 // This should only be necessary for MinGW, since it doesn't have a dwmapi.h. Add another #ifdef if you like.
129 extern "C"
130 {
131 typedef HRESULT(WINAPI *t_DwmFlush)();
132 typedef HRESULT(WINAPI *t_DwmIsCompositionEnabled)(BOOL *pfEnabled);
133 }
134
135 void do_DwmFlush()
136 {
137 static HMODULE shell = LoadLibrary("dwmapi.dll");
138
139 if(!shell)
140 return;
141
142 static t_DwmFlush flush=reinterpret_cast<t_DwmFlush>(GetProcAddress(shell, "DwmFlush"));
143 static t_DwmIsCompositionEnabled isEnabled=reinterpret_cast<t_DwmIsCompositionEnabled>(GetProcAddress(shell, "DwmIsCompositionEnabled"));
144
145 BOOL enabled;
146 isEnabled(&enabled);
147
148 if(isEnabled)
149 flush();
150 }
151
152 #endif // _WIN32
153
154 325 void zc_exit(int code)
155 {
156 extern CConsoleLoggerEx zscript_coloured_console;
157
158 325 set_is_exiting();
159
160
1/2
✓ Branch 0 taken 325 times.
✗ Branch 1 not taken.
325 if (replay_get_mode() == ReplayMode::Record) replay_save();
161 325 replay_stop();
162 325 music_stop();
163 325 kill_sfx();
164
165
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 309 times.
325 if (get_qr(qr_OLD_SCRIPT_VOLUME))
166 {
167 //restore user volume settings
168
2/2
✓ Branch 0 taken 308 times.
✓ Branch 1 taken 1 times.
309 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
169 {
170 1 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
171 1 }
172
2/2
✓ Branch 0 taken 308 times.
✓ Branch 1 taken 1 times.
309 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
173 {
174 1 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
175 1 }
176
2/2
✓ Branch 0 taken 308 times.
✓ Branch 1 taken 1 times.
309 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
177 {
178 1 emusic_volume = (int32_t)FFCore.usr_music_volume;
179 1 }
180
1/2
✓ Branch 0 taken 309 times.
✗ Branch 1 not taken.
309 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
181 {
182 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
183 }
184 309 }
185
1/2
✓ Branch 0 taken 325 times.
✗ Branch 1 not taken.
325 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
186 {
187 pan_style = (int32_t)FFCore.usr_panstyle;
188 }
189 325 save_game_configs();
190
191 325 zscript_coloured_console.kill();
192 325 zasm_pipeline_shutdown();
193 325 frame_timings_end();
194 325 quit_game();
195
196 325 Z_message("ZQuest Classic website: https://zquestclassic.com\n");
197 325 Z_message("ZQuest Classic docs: https://docs.zquestclassic.com\n");
198
199 325 allegro_exit();
200 325 exit(code);
201 }
202
203 93594 bool flash_reduction_enabled(bool check_qr)
204 {
205
4/4
✓ Branch 0 taken 88914 times.
✓ Branch 1 taken 4680 times.
✓ Branch 2 taken 87624 times.
✓ Branch 3 taken 92304 times.
93594 return (check_qr && get_qr(qr_EPILEPSY)) || epilepsyFlashReduction || replay_is_debug();
206 }
207
208 // Dialogue largening
209 void large_dialog(DIALOG *d)
210 {
211 large_dialog(d, 1.5);
212 }
213
214 void large_dialog(DIALOG *d, float RESIZE_AMT)
215 {
216 if(!d[0].d1)
217 {
218 d[0].d1 = 1;
219 int32_t oldwidth = d[0].w;
220 int32_t oldheight = d[0].h;
221 int32_t oldx = d[0].x;
222 int32_t oldy = d[0].y;
223 d[0].x -= int32_t(d[0].w/RESIZE_AMT);
224 d[0].y -= int32_t(d[0].h/RESIZE_AMT);
225 d[0].w = int32_t(d[0].w*RESIZE_AMT);
226 d[0].h = int32_t(d[0].h*RESIZE_AMT);
227
228 for(int32_t i=1; d[i].proc !=NULL; i++)
229 {
230 // Place elements horizontally
231 double xpc = ((double)(d[i].x - oldx) / (double)oldwidth);
232 d[i].x = int32_t(d[0].x + (xpc*d[0].w));
233
234 if(d[i].proc != d_stringloader)
235 {
236 if(d[i].proc==d_bitmap_proc)
237 {
238 d[i].w *= 2;
239 }
240 else d[i].w = int32_t(d[i].w*RESIZE_AMT);
241 }
242
243 // Place elements vertically
244 double ypc = ((double)(d[i].y - oldy) / (double)oldheight);
245 d[i].y = int32_t(d[0].y + (ypc*d[0].h));
246
247 // Vertically resize elements
248 if(d[i].proc == jwin_edit_proc || d[i].proc == jwin_check_proc || d[i].proc == jwin_checkfont_proc)
249 {
250 d[i].h = int32_t((double)d[i].h*1.5);
251 }
252 else if(d[i].proc == jwin_droplist_proc || d[i].proc == d_joylist_proc)
253 {
254 d[i].y += int32_t((double)d[i].h*0.25);
255 d[i].h = int32_t((double)d[i].h*1.25);
256 }
257 else if(d[i].proc==d_bitmap_proc)
258 {
259 d[i].h *= 2;
260 }
261 else d[i].h = int32_t(d[i].h*RESIZE_AMT);
262
263 // Fix frames
264 if(d[i].proc == jwin_frame_proc)
265 {
266 d[i].x++;
267 d[i].y++;
268 d[i].w-=4;
269 d[i].h-=4;
270 }
271 }
272 }
273
274 for(int32_t i=1; d[i].proc!=NULL; i++)
275 {
276 if(d[i].proc==jwin_slider_proc)
277 continue;
278
279 // Bigger font
280 bool bigfontproc = (d[i].proc != d_midilist_proc && d[i].proc != jwin_droplist_proc && d[i].proc != jwin_abclist_proc && d[i].proc != jwin_list_proc && d[i].proc != d_joylist_proc);
281
282 if(!d[i].dp2 && bigfontproc)
283 {
284 d[i].dp2 = get_zc_font(font_lfont_l);
285 }
286 else if(!bigfontproc)
287 {
288 ((ListData *)d[i].dp)->font = &a4fonts[font_lfont_l];
289 }
290
291 // Make checkboxes work
292 if(d[i].proc == jwin_check_proc)
293 d[i].proc = jwin_checkfont_proc;
294 else if(d[i].proc == jwin_radio_proc)
295 d[i].proc = jwin_radiofont_proc;
296 }
297
298 jwin_center_dialog(d);
299 }
300
301 static char cfg_sect[] = "zeldadx"; //We need to rename this.
302 static char ctrl_sect[] = "Controls";
303 static char sfx_sect[] = "Volume";
304
305 int32_t d_dummy_proc(int32_t,DIALOG *,int32_t)
306 {
307 return D_O_K;
308 }
309
310 bool is_reserved_key(int c)
311 {
312 switch(c)
313 {
314 case KEY_ESC:
315 return true;
316 }
317 return false;
318 }
319 bool is_reserved_keycombo(int c, int modflag)
320 {
321 if(c==KEY_F4 && (modflag&KB_ALT_FLAG))
322 return true;
323 return false;
324 }
325 bool checkcheat(Cheat cheat)
326 {
327 if(cheatkeys[cheat][0] && zc_readkey(cheatkeys[cheat][0]))
328 return true; //Main key pressed
329 if(cheatkeys[cheat][1] && zc_readkey(cheatkeys[cheat][1]))
330 return true; //Alt key pressed
331 return false;
332 }
333 325 void load_default_cheatkeys()
334 {
335 325 memset(cheatkeys, 0, sizeof(cheatkeys));
336 325 cheatkeys[Cheat::Life][0] = KEY_H;
337 325 cheatkeys[Cheat::Life][1] = KEY_ASTERISK;
338 325 cheatkeys[Cheat::Magic][0] = KEY_M;
339 325 cheatkeys[Cheat::Magic][1] = KEY_SLASH_PAD;
340 325 cheatkeys[Cheat::Rupies][0] = KEY_R;
341 325 cheatkeys[Cheat::Bombs][0] = KEY_B;
342 325 cheatkeys[Cheat::Arrows][0] = KEY_A;
343 325 cheatkeys[Cheat::Clock][0] = KEY_I;
344 325 cheatkeys[Cheat::Walls][0] = KEY_F11;
345 325 cheatkeys[Cheat::Fast][0] = KEY_Q;
346 325 cheatkeys[Cheat::Light][0] = KEY_L;
347 325 cheatkeys[Cheat::IgnoreSideView][0] = KEY_V;
348 325 cheatkeys[Cheat::Kill][0] = KEY_K;
349 325 cheatkeys[Cheat::GoTo][0] = KEY_G;
350 325 cheatkeys[Cheat::TrigSecrets][0] = KEY_S;
351 325 cheatkeys[Cheat::ShowL0][0] = KEY_0;
352 325 cheatkeys[Cheat::ShowL1][0] = KEY_1;
353 325 cheatkeys[Cheat::ShowL2][0] = KEY_2;
354 325 cheatkeys[Cheat::ShowL3][0] = KEY_3;
355 325 cheatkeys[Cheat::ShowL4][0] = KEY_4;
356 325 cheatkeys[Cheat::ShowL5][0] = KEY_5;
357 325 cheatkeys[Cheat::ShowL6][0] = KEY_6;
358 325 cheatkeys[Cheat::ShowFFC][0] = KEY_7;
359 325 cheatkeys[Cheat::ShowSprites][0] = KEY_8;
360 325 cheatkeys[Cheat::ShowWalkability][0] = KEY_W;
361 325 cheatkeys[Cheat::ShowEffects][0] = KEY_E;
362 325 cheatkeys[Cheat::ShowOverhead][0] = KEY_O;
363 325 cheatkeys[Cheat::ShowPushblock][0] = KEY_P;
364 325 cheatkeys[Cheat::ShowHitbox][0] = KEY_C;
365 325 cheatkeys[Cheat::ShowFFCScripts][0] = KEY_F;
366 325 }
367
368 static bool loaded_game_configs;
369
370 325 void load_game_configs()
371 {
372 325 loaded_game_configs = true;
373 325 joystick_index = zc_get_config(ctrl_sect,"joystick_index",0);
374 325 js_stick_1_x_stick = zc_get_config(ctrl_sect,"js_stick_1_x_stick",0);
375 325 js_stick_1_x_axis = zc_get_config(ctrl_sect,"js_stick_1_x_axis",0);
376 325 js_stick_1_x_offset = zc_get_config(ctrl_sect,"js_stick_1_x_offset",0) ? 128 : 0;
377 325 js_stick_1_y_stick = zc_get_config(ctrl_sect,"js_stick_1_y_stick",0);
378 325 js_stick_1_y_axis = zc_get_config(ctrl_sect,"js_stick_1_y_axis",1);
379 325 js_stick_1_y_offset = zc_get_config(ctrl_sect,"js_stick_1_y_offset",0) ? 128 : 0;
380 325 js_stick_2_x_stick = zc_get_config(ctrl_sect,"js_stick_2_x_stick",1);
381 325 js_stick_2_x_axis = zc_get_config(ctrl_sect,"js_stick_2_x_axis",0);
382 325 js_stick_2_x_offset = zc_get_config(ctrl_sect,"js_stick_2_x_offset",0) ? 128 : 0;
383 325 js_stick_2_y_stick = zc_get_config(ctrl_sect,"js_stick_2_y_stick",1);
384 325 js_stick_2_y_axis = zc_get_config(ctrl_sect,"js_stick_2_y_axis",1);
385 325 js_stick_2_y_offset = zc_get_config(ctrl_sect,"js_stick_2_y_offset",0) ? 128 : 0;
386 325 analog_movement = (zc_get_config(ctrl_sect,"analog_movement",1));
387
388 //cheat modifier keya
389 325 cheat_modifier_keys[0] = zc_get_config(ctrl_sect,"key_cheatmod_a1",KEY_ZC_LCONTROL);
390 325 cheat_modifier_keys[1] = zc_get_config(ctrl_sect,"key_cheatmod_a2",0);
391 325 cheat_modifier_keys[2] = zc_get_config(ctrl_sect,"key_cheatmod_b1",KEY_ZC_RCONTROL);
392 325 cheat_modifier_keys[3] = zc_get_config(ctrl_sect,"key_cheatmod_b2",0);
393
394 //cheat keys
395 325 load_default_cheatkeys();
396 char buf[256];
397
2/2
✓ Branch 0 taken 325 times.
✓ Branch 1 taken 11700 times.
12025 for(size_t q = 1; q < Cheat::Last; ++q)
398 {
399
1/2
✓ Branch 0 taken 11700 times.
✗ Branch 1 not taken.
11700 if(!bindable_cheat((Cheat)q)) continue;
400 11700 std::string cheatname = cheat_to_string((Cheat)q);
401
1/2
✓ Branch 0 taken 11700 times.
✗ Branch 1 not taken.
11700 util::lowerstr(cheatname);
402 11700 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
403
1/2
✓ Branch 0 taken 11700 times.
✗ Branch 1 not taken.
11700 cheatkeys[q][0] = zc_get_config(ctrl_sect,buf,cheatkeys[q][0]);
404 11700 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
405
1/2
✓ Branch 0 taken 11700 times.
✗ Branch 1 not taken.
11700 cheatkeys[q][1] = zc_get_config(ctrl_sect,buf,cheatkeys[q][1]);
406 11700 }
407
408
1/2
✓ Branch 0 taken 325 times.
✗ Branch 1 not taken.
325 if((uint32_t)joystick_index >= MAX_JOYSTICKS)
409 joystick_index = 0;
410
411 325 Akey = zc_get_config(ctrl_sect,"key_a",KEY_Z);
412 325 Bkey = zc_get_config(ctrl_sect,"key_b",KEY_X);
413 325 Skey = zc_get_config(ctrl_sect,"key_s",KEY_ENTER);
414 325 Lkey = zc_get_config(ctrl_sect,"key_l",KEY_Q);
415 325 Rkey = zc_get_config(ctrl_sect,"key_r",KEY_W);
416 325 Pkey = zc_get_config(ctrl_sect,"key_p",KEY_SPACE);
417 325 Exkey1 = zc_get_config(ctrl_sect,"key_ex1",KEY_A);
418 325 Exkey2 = zc_get_config(ctrl_sect,"key_ex2",KEY_S);
419 325 Exkey3 = zc_get_config(ctrl_sect,"key_ex3",KEY_D);
420 325 Exkey4 = zc_get_config(ctrl_sect,"key_ex4",KEY_C);
421
422 325 DUkey = zc_get_config(ctrl_sect,"key_up", KEY_UP);
423 325 DDkey = zc_get_config(ctrl_sect,"key_down", KEY_DOWN);
424 325 DLkey = zc_get_config(ctrl_sect,"key_left", KEY_LEFT);
425 325 DRkey = zc_get_config(ctrl_sect,"key_right",KEY_RIGHT);
426
427 325 Abtn = zc_get_config(ctrl_sect,"btn_a",2);
428 325 Bbtn = zc_get_config(ctrl_sect,"btn_b",1);
429 325 Sbtn = zc_get_config(ctrl_sect,"btn_s",10);
430 325 Mbtn = zc_get_config(ctrl_sect,"btn_m",9);
431 325 Lbtn = zc_get_config(ctrl_sect,"btn_l",5);
432 325 Rbtn = zc_get_config(ctrl_sect,"btn_r",6);
433 325 Pbtn = zc_get_config(ctrl_sect,"btn_p",12);
434 325 Exbtn1 = zc_get_config(ctrl_sect,"btn_ex1",7);
435 325 Exbtn2 = zc_get_config(ctrl_sect,"btn_ex2",8);
436 325 Exbtn3 = zc_get_config(ctrl_sect,"btn_ex3",4);
437 325 Exbtn4 = zc_get_config(ctrl_sect,"btn_ex4",3);
438
439 325 DUbtn = zc_get_config(ctrl_sect,"btn_up",13);
440 325 DDbtn = zc_get_config(ctrl_sect,"btn_down",14);
441 325 DLbtn = zc_get_config(ctrl_sect,"btn_left",15);
442 325 DRbtn = zc_get_config(ctrl_sect,"btn_right",16);
443
444 325 epilepsyFlashReduction = zc_get_config(cfg_sect,"epilepsy_flash_reduction",0);
445
446 325 midi_volume = zc_get_config(sfx_sect,"midi",255);
447 325 sfx_volume = zc_get_config(sfx_sect,"sfx",255);
448 325 emusic_volume = zc_get_config(sfx_sect,"emusic",255);
449 325 pan_style = zc_get_config(sfx_sect,"pan",1);
450 325 volkeys = zc_get_config(sfx_sect,"volkeys",0)!=0;
451 325 zc_vsync = zc_get_config(cfg_sect,"vsync",0);
452 325 Throttlefps = zc_get_config(cfg_sect,"throttlefps",1)!=0;
453 325 Maxfps = zc_get_config(cfg_sect,"maxfps",0);
454 325 TransLayers = zc_get_config(cfg_sect,"translayers",1)!=0;
455 325 SnapshotFormat = zc_get_config(cfg_sect,"snapshot_format",3);
456 325 ShowBottomPixels = zc_get_config(cfg_sect,"bottom_8_px",0);
457 325 SnapshotScale = zc_get_config(cfg_sect,"snapshot_scale",2);
458 325 NameEntryMode = zc_get_config(cfg_sect,"name_entry_mode",0);
459 #ifdef __EMSCRIPTEN__
460 if (em_is_mobile()) NameEntryMode = 2;
461 #endif
462 325 ShowFPS = zc_get_config(cfg_sect,"showfps",0)!=0;
463 325 ShowGameTime = zc_get_config(cfg_sect,"showtime",0);
464 325 NESquit = zc_get_config(cfg_sect,"fastquit",0)!=0;
465 325 ClickToFreeze = zc_get_config(cfg_sect,"clicktofreeze",1)!=0;
466 325 abc_patternmatch = zc_get_config(cfg_sect, "lister_pattern_matching", 1);
467 325 pause_in_background = zc_get_config(cfg_sect, "pause_in_background", 0);
468
469 325 window_width = resx = zc_get_config(cfg_sect,"window_width",-1);
470 325 window_height = resy = zc_get_config(cfg_sect,"window_height",-1);
471 325 SaveDragResize = zc_get_config(cfg_sect,"save_drag_resize",0)!=0;
472 325 DragAspect = zc_get_config(cfg_sect,"drag_aspect",0)!=0;
473 325 SaveWinPos = zc_get_config(cfg_sect,"save_window_position",0)!=0;
474 325 scaleForceInteger = zc_get_config("zeldadx","scaling_force_integer",1)!=0;
475 325 stretchGame = zc_get_config("zeldadx","stretch_game_area",0)!=0;
476
477 325 loadlast = zc_get_config(cfg_sect,"load_last_path","");
478
479 325 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
480
481 325 info_opacity = zc_get_config("zc","debug_info_opacity",255);
482 #ifdef _WIN32
483 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
484 //use_win7_keyboard_fix = (byte) zc_get_config(cfg_sect,"use_win7_key_fix",0);
485 use_win32_proc = (byte) zc_get_config(cfg_sect,"zc_win_proc_fix",0); //buggy
486
487 // This one's for Aero
488 use_dwm_flush = (byte) zc_get_config("zeldadx","use_dwm_flush",0);
489
490 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
491 #else //UNIX
492 325 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
493 325 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
494 #endif
495 325 clearConsoleOnLoad = zc_get_config("CONSOLE","clear_console_on_load",1)!=0;
496 325 clearConsoleOnReload = zc_get_config("CONSOLE","clear_console_on_reload",0)!=0;
497
498 325 strcpy(qstdir,zc_get_config(cfg_sect,"quest_dir","quests"));
499 325 strcpy(qstpath,qstdir); //qstpath is the local (for this run of ZC) quest path, qstdir is the universal quest dir.
500 325 ss_enable = zc_get_config(cfg_sect,"ss_enable",1) ? 1 : 0;
501 325 ss_after = vbound(zc_get_config(cfg_sect,"ss_after",14), 0, 14);
502 325 ss_speed = vbound(zc_get_config(cfg_sect,"ss_speed",2), 0, 6);
503 325 ss_density = vbound(zc_get_config(cfg_sect,"ss_density",3), 0, 6);
504 325 heart_beep = zc_get_config(cfg_sect,"heart_beep",0)!=0;
505 //gui_colorset = zc_get_config(cfg_sect,"gui_colorset",0);
506 325 sfxdat = zc_get_config(cfg_sect,"use_sfx_dat",1); // TODO: sfxdat is always set to 1 for titlescreen... and 0 in readsfx... so this cfg is pointless, remove?
507 325 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
508 325 use_save_indicator = zc_get_config(cfg_sect,"save_indicator",0);
509 325 zc_192b163_warp_compatibility = zc_get_config(cfg_sect,"zc_192b163_warp_compatibility",0);
510 325 SkipTitle = zc_get_config(cfg_sect,"skip_title",0);
511 325 }
512
513 void save_control_configs(bool kb)
514 {
515 if(kb)
516 {
517 zc_set_config(ctrl_sect,"key_cheatmod_a1",cheat_modifier_keys[0]);
518 zc_set_config(ctrl_sect,"key_cheatmod_a2",cheat_modifier_keys[1]);
519 zc_set_config(ctrl_sect,"key_cheatmod_b1",cheat_modifier_keys[2]);
520 zc_set_config(ctrl_sect,"key_cheatmod_b2",cheat_modifier_keys[3]);
521
522 if (!replay_is_replaying())
523 {
524 zc_set_config(ctrl_sect,"key_a",Akey);
525 zc_set_config(ctrl_sect,"key_b",Bkey);
526 zc_set_config(ctrl_sect,"key_s",Skey);
527 zc_set_config(ctrl_sect,"key_l",Lkey);
528 zc_set_config(ctrl_sect,"key_r",Rkey);
529 zc_set_config(ctrl_sect,"key_p",Pkey);
530 zc_set_config(ctrl_sect,"key_ex1",Exkey1);
531 zc_set_config(ctrl_sect,"key_ex2",Exkey2);
532 zc_set_config(ctrl_sect,"key_ex3",Exkey3);
533 zc_set_config(ctrl_sect,"key_ex4",Exkey4);
534 zc_set_config(ctrl_sect,"key_up", DUkey);
535 zc_set_config(ctrl_sect,"key_down", DDkey);
536 zc_set_config(ctrl_sect,"key_left", DLkey);
537 zc_set_config(ctrl_sect,"key_right",DRkey);
538 }
539 }
540 else
541 {
542 zc_set_config(ctrl_sect,"joystick_index",joystick_index);
543 zc_set_config(ctrl_sect,"js_stick_1_x_stick",js_stick_1_x_stick);
544 zc_set_config(ctrl_sect,"js_stick_1_x_axis",js_stick_1_x_axis);
545 zc_set_config(ctrl_sect,"js_stick_1_x_offset",js_stick_1_x_offset ? 1 : 0);
546 zc_set_config(ctrl_sect,"js_stick_1_y_stick",js_stick_1_y_stick);
547 zc_set_config(ctrl_sect,"js_stick_1_y_axis",js_stick_1_y_axis);
548 zc_set_config(ctrl_sect,"js_stick_1_y_offset",js_stick_1_y_offset ? 1 : 0);
549 zc_set_config(ctrl_sect,"js_stick_2_x_stick",js_stick_2_x_stick);
550 zc_set_config(ctrl_sect,"js_stick_2_x_axis",js_stick_2_x_axis);
551 zc_set_config(ctrl_sect,"js_stick_2_x_offset",js_stick_2_x_offset ? 1 : 0);
552 zc_set_config(ctrl_sect,"js_stick_2_y_stick",js_stick_2_y_stick);
553 zc_set_config(ctrl_sect,"js_stick_2_y_axis",js_stick_2_y_axis);
554 zc_set_config(ctrl_sect,"js_stick_2_y_offset",js_stick_2_y_offset ? 1 : 0);
555 zc_set_config(ctrl_sect,"analog_movement",analog_movement);
556
557 zc_set_config(ctrl_sect,"btn_a",Abtn);
558 zc_set_config(ctrl_sect,"btn_b",Bbtn);
559 zc_set_config(ctrl_sect,"btn_s",Sbtn);
560 zc_set_config(ctrl_sect,"btn_m",Mbtn);
561 zc_set_config(ctrl_sect,"btn_l",Lbtn);
562 zc_set_config(ctrl_sect,"btn_r",Rbtn);
563 zc_set_config(ctrl_sect,"btn_p",Pbtn);
564 zc_set_config(ctrl_sect,"btn_ex1",Exbtn1);
565 zc_set_config(ctrl_sect,"btn_ex2",Exbtn2);
566 zc_set_config(ctrl_sect,"btn_ex3",Exbtn3);
567 zc_set_config(ctrl_sect,"btn_ex4",Exbtn4);
568
569 zc_set_config(ctrl_sect,"btn_up",DUbtn);
570 zc_set_config(ctrl_sect,"btn_down",DDbtn);
571 zc_set_config(ctrl_sect,"btn_left",DLbtn);
572 zc_set_config(ctrl_sect,"btn_right",DRbtn);
573 }
574 }
575
576 void save_cheatkeys()
577 {
578 char buf[256];
579 for(size_t q = 1; q < Cheat::Last; ++q)
580 {
581 if(!bindable_cheat((Cheat)q)) continue;
582 std::string cheatname = cheat_to_string((Cheat)q);
583 util::lowerstr(cheatname);
584 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
585 zc_set_config(ctrl_sect,buf,cheatkeys[q][0]);
586 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
587 if(cheatkeys[q][1])
588 zc_set_config(ctrl_sect,buf,cheatkeys[q][1]);
589 else zc_set_config(ctrl_sect,buf,(char*)nullptr);
590 }
591 }
592
593 325 void save_game_configs()
594 {
595
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 325 times.
325 if (!loaded_game_configs) return;
596
597 325 packfile_password("");
598
599
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 325 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
325 if (all_get_display() && !all_get_fullscreen_flag()&& SaveWinPos)
600 {
601 int o_window_x, o_window_y;
602 al_get_window_position(all_get_display(), &o_window_x, &o_window_y);
603 zc_set_config(cfg_sect,"window_x",o_window_x);
604 zc_set_config(cfg_sect,"window_y",o_window_y);
605 }
606
607
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 325 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
325 if (all_get_display() && !all_get_fullscreen_flag() && SaveDragResize)
608 {
609 window_width = al_get_display_width(all_get_display());
610 window_height = al_get_display_height(all_get_display());
611 zc_set_config(cfg_sect,"window_width",window_width);
612 zc_set_config(cfg_sect,"window_height",window_height);
613 }
614
615 325 zc_set_config(cfg_sect,"load_last_path",loadlast.c_str());
616 325 zc_set_config(cfg_sect,"use_sfx_dat",sfxdat);
617
618 325 flush_config_file();
619 #ifdef __EMSCRIPTEN__
620 em_sync_fs();
621 #endif
622 325 }
623
624 //----------------------------------------------------------------
625
626 // Timers
627
628 42038 void fps_callback()
629 {
630 42038 lastfps=framecnt;
631 42038 framecnt=0;
632 42038 }
633
634 END_OF_FUNCTION(fps_callback)
635
636 325 int32_t Z_init_timers()
637 {
638 static bool didit = false;
639 const static char *err_str = "Couldn't allocate timer";
640 325 err_str = err_str; //Unused variable warning
641
642
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 325 times.
325 if(didit)
643 return 1;
644
645 325 didit = true;
646
647 LOCK_VARIABLE(lastfps);
648 LOCK_VARIABLE(framecnt);
649 LOCK_FUNCTION(fps_callback);
650
651
1/2
✓ Branch 0 taken 325 times.
✗ Branch 1 not taken.
325 if(install_int_ex(fps_callback,SECS_TO_TIMER(1)))
652 return 0;
653
654 325 return 1;
655 325 }
656
657 325 void Z_remove_timers()
658 {
659 325 remove_int(fps_callback);
660 325 }
661
662 //----------------------------------------------------------------
663
664 void dump_pal(BITMAP *dest)
665 {
666 for(int32_t i=0; i<256; i++)
667 rectfill(dest,(i&63)<<2,(i&0xFC0)>>4,((i&63)<<2)+3,((i&0xFC0)>>4)+3,i);
668 }
669
670 //----------------------------------------------------------------
671
672 int game_mouse_index = ZCM_BLANK;
673 static bool system_mouse = false;
674 118 bool sys_mouse()
675 {
676 118 system_mouse = true;
677 118 return MouseSprite::set(ZCM_NORMAL);
678 }
679 1702 bool game_mouse()
680 {
681 1702 system_mouse = false;
682 1702 return MouseSprite::set(game_mouse_index);
683 }
684 void custom_mouse(BITMAP* bmp, int fx, int fy, bool sys_recolor, bool user_scale)
685 {
686 if(!bmp)
687 return;
688 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
689 int scaledw = bmp->w*scale, scaledh = bmp->h*scale;
690 if(bmp->w == scaledw && bmp->h == scaledh)
691 user_scale = false;
692 if(user_scale || sys_recolor)
693 {
694 if(!user_scale) scale = 1;
695 BITMAP* tmpbmp = create_bitmap_ex(8,bmp->w*scale,bmp->h*scale);
696 if(user_scale)
697 stretch_blit(bmp, tmpbmp, 0, 0, bmp->w, bmp->h, 0, 0, tmpbmp->w, tmpbmp->h);
698 else
699 blit(bmp, tmpbmp, 0, 0, 0, 0, bmp->w, bmp->h);
700 if(sys_recolor)
701 recolor_mouse(tmpbmp);
702 MouseSprite::assign(ZCM_CUSTOM, tmpbmp, fx*scale, fy*scale);
703 destroy_bitmap(tmpbmp);
704 }
705 else
706 {
707 MouseSprite::assign(ZCM_CUSTOM, bmp, fx, fy);
708 }
709 }
710
711 //Handles converting the mouse sprite from the .dat file
712 void recolor_mouse(BITMAP* bmp)
713 {
714 for(int32_t x = 0; x < bmp->w; ++x)
715 {
716 for(int32_t y = 0; y < bmp->h; ++y)
717 {
718 int32_t color = getpixel(bmp, x, y);
719 switch(color)
720 {
721 case dvc(1):
722 color = jwin_pal[jcCURSORMISC];
723 break;
724 case dvc(2):
725 color = jwin_pal[jcCURSOROUTLINE];
726 break;
727 case dvc(3):
728 color = jwin_pal[jcCURSORLIGHT];
729 break;
730 case dvc(5):
731 color = jwin_pal[jcCURSORDARK];
732 break;
733 default:
734 continue;
735 }
736 putpixel(bmp, x, y, color);
737 }
738 }
739 }
740 void load_mouse()
741 {
742 PALETTE pal;
743 BITMAP* cursor_bitmap = load_bitmap("assets/cursor.bmp", pal);
744 if (!cursor_bitmap)
745 Z_error_fatal("Missing required file %s\n", "assets/cursor.bmp");
746
747 enter_sys_pal();
748 MouseSprite::set(-1);
749 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
750 int32_t sz = 16*scale;
751 for(int32_t j = 0; j < 1; ++j)
752 {
753 BITMAP* tmpbmp = create_bitmap_ex(8,16,16);
754 if(zcmouse[j])
755 destroy_bitmap(zcmouse[j]);
756 zcmouse[j] = create_bitmap_ex(8,sz,sz);
757 clear_bitmap(zcmouse[j]);
758 clear_bitmap(tmpbmp);
759 blit(cursor_bitmap,tmpbmp,1,j*17+1,0,0,16,16);
760 recolor_mouse(tmpbmp);
761 if(sz!=16)
762 stretch_blit(tmpbmp, zcmouse[j], 0, 0, 16, 16, 0, 0, sz, sz);
763 else
764 blit(tmpbmp, zcmouse[j], 0, 0, 0, 0, 16, 16);
765 destroy_bitmap(tmpbmp);
766 }
767 if(!hw_palette) hw_palette = &RAMpal;
768 zc_set_palette(*hw_palette);
769
770 BITMAP* blankmouse = create_bitmap_ex(8,16,16);
771 clear_bitmap(blankmouse);
772
773 MouseSprite::assign(ZCM_NORMAL, zcmouse[0], 1*scale, 1*scale);
774 MouseSprite::assign(ZCM_BLANK, blankmouse);
775 //Don't assign ZCM_CUSTOM. That'll be handled by scripts.
776
777 //Reload the mouse
778 if(system_mouse)
779 sys_mouse();
780 else game_mouse();
781
782 destroy_bitmap(blankmouse);
783 destroy_bitmap(cursor_bitmap);
784 exit_sys_pal();
785 }
786
787 // sets the video mode and initializes the palette and mouse sprite
788 325 bool game_vid_mode(int32_t mode,int32_t wait)
789 {
790
1/2
✓ Branch 0 taken 325 times.
✗ Branch 1 not taken.
325 if (is_headless())
791 325 return true;
792
793 extern int zq_screen_w, zq_screen_h;
794 if(set_gfx_mode(mode,resx,resy,zq_screen_w,zq_screen_h)!=0)
795 {
796 return false;
797 }
798
799 scrx = (resx-320)>>1;
800 scry = (resy-240)>>1;
801 for(int32_t q = 0; q < NUM_ZCMOUSE; ++q)
802 zcmouse[q] = NULL;
803 load_mouse();
804
805 for(int32_t i=240; i<256; i++)
806 RAMpal[i]=pal_gui[i];
807
808 zc_set_palette(RAMpal);
809 clear_to_color(screen,BLACK);
810
811 rest(wait);
812 return true;
813 325 }
814
815 333 void null_quest()
816 {
817
1/2
✓ Branch 0 taken 333 times.
✗ Branch 1 not taken.
333 std::string title_assets_path = "modules/classic/title_gfx.dat";
818
2/4
✓ Branch 0 taken 333 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 333 times.
333 if (get_last_loaded_qstpath() == title_assets_path)
819 return;
820
821 byte skip_flags[4];
822
2/2
✓ Branch 0 taken 333 times.
✓ Branch 1 taken 8658 times.
8991 for (int i = 0; i < skip_max; i++)
823
1/2
✓ Branch 0 taken 8658 times.
✗ Branch 1 not taken.
8658 set_bit(skip_flags, i, 1);
824
1/2
✓ Branch 0 taken 333 times.
✗ Branch 1 not taken.
333 set_bit(skip_flags, skip_tiles, 0);
825
1/2
✓ Branch 0 taken 333 times.
✗ Branch 1 not taken.
333 set_bit(skip_flags, skip_csets, 0);
826
1/2
✓ Branch 0 taken 333 times.
✗ Branch 1 not taken.
333 set_bit(skip_flags, skip_misc, 0); // needed for miscsfx (skip this and `tests/replays/demons_inferno/demons_inferno_1_of_2.zplay` fails).
827
1/2
✓ Branch 0 taken 333 times.
✗ Branch 1 not taken.
333 loadquest(title_assets_path.c_str(), &QHeader, &QMisc, tunes+ZC_MIDI_COUNT, false, skip_flags, 0, false);
828 333 sfxdat = 1;
829 // TODO: sfx.dat is ~1.2 MB. Could be better to break that up into individual files and load on demand / not at startup.
830 // TODO: can we cache the tiles/colordata so we don't have to read title_gfx.dat more than once?
831 // colordata is tiny, but tilebuf is huge, so limit that to just what the title screen needs.
832 // Another option: embed this data into the binary (`xxd -i resources/modules/classic/title_gfx.dat > title_gfx.h`)
833
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 333 times.
333 }
834
835 333 void init_NES_mode()
836 {
837 333 null_quest();
838 333 }
839
840 //----------------------------------------------------------------
841
842 qword trianglelines[16]=
843 {
844 0x0000000000000000ULL,
845 0xFD00000000000000ULL,
846 0xFDFD000000000000ULL,
847 0xFDFDFD0000000000ULL,
848 0xFDFDFDFD00000000ULL,
849 0xFDFDFDFDFD000000ULL,
850 0xFDFDFDFDFDFD0000ULL,
851 0xFDFDFDFDFDFDFD00ULL,
852 0xFDFDFDFDFDFDFDFDULL,
853 0x00FDFDFDFDFDFDFDULL,
854 0x0000FDFDFDFDFDFDULL,
855 0x000000FDFDFDFDFDULL,
856 0x00000000FDFDFDFDULL,
857 0x0000000000FDFDFDULL,
858 0x000000000000FDFDULL,
859 0x00000000000000FDULL,
860 };
861
862 word screen_triangles[29][32];
863
864 // the ULL suffixes are to prevent this warning:
865 // warning: integer constant is too large for "int32_t" type
866
867 qword triangles[4][16][8]= //[direction][value][line]
868 {
869 {
870 {
871 0x0000000000000000ULL,
872 0x0000000000000000ULL,
873 0x0000000000000000ULL,
874 0x0000000000000000ULL,
875 0x0000000000000000ULL,
876 0x0000000000000000ULL,
877 0x0000000000000000ULL,
878 0x0000000000000000ULL
879 },
880 {
881 0xFD00000000000000ULL,
882 0x0000000000000000ULL,
883 0x0000000000000000ULL,
884 0x0000000000000000ULL,
885 0x0000000000000000ULL,
886 0x0000000000000000ULL,
887 0x0000000000000000ULL,
888 0x0000000000000000ULL
889 },
890 {
891 0xFDFD000000000000ULL,
892 0xFD00000000000000ULL,
893 0x0000000000000000ULL,
894 0x0000000000000000ULL,
895 0x0000000000000000ULL,
896 0x0000000000000000ULL,
897 0x0000000000000000ULL,
898 0x0000000000000000ULL
899 },
900 {
901 0xFDFDFD0000000000ULL,
902 0xFDFD000000000000ULL,
903 0xFD00000000000000ULL,
904 0x0000000000000000ULL,
905 0x0000000000000000ULL,
906 0x0000000000000000ULL,
907 0x0000000000000000ULL,
908 0x0000000000000000ULL
909 },
910 {
911 0xFDFDFDFD00000000ULL,
912 0xFDFDFD0000000000ULL,
913 0xFDFD000000000000ULL,
914 0xFD00000000000000ULL,
915 0x0000000000000000ULL,
916 0x0000000000000000ULL,
917 0x0000000000000000ULL,
918 0x0000000000000000ULL
919 },
920 {
921 0xFDFDFDFDFD000000ULL,
922 0xFDFDFDFD00000000ULL,
923 0xFDFDFD0000000000ULL,
924 0xFDFD000000000000ULL,
925 0xFD00000000000000ULL,
926 0x0000000000000000ULL,
927 0x0000000000000000ULL,
928 0x0000000000000000ULL
929 },
930 {
931 0xFDFDFDFDFDFD0000ULL,
932 0xFDFDFDFDFD000000ULL,
933 0xFDFDFDFD00000000ULL,
934 0xFDFDFD0000000000ULL,
935 0xFDFD000000000000ULL,
936 0xFD00000000000000ULL,
937 0x0000000000000000ULL,
938 0x0000000000000000ULL
939 },
940 {
941 0xFDFDFDFDFDFDFD00ULL,
942 0xFDFDFDFDFDFD0000ULL,
943 0xFDFDFDFDFD000000ULL,
944 0xFDFDFDFD00000000ULL,
945 0xFDFDFD0000000000ULL,
946 0xFDFD000000000000ULL,
947 0xFD00000000000000ULL,
948 0x0000000000000000ULL
949 },
950 {
951 0xFDFDFDFDFDFDFDFDULL,
952 0xFDFDFDFDFDFDFD00ULL,
953 0xFDFDFDFDFDFD0000ULL,
954 0xFDFDFDFDFD000000ULL,
955 0xFDFDFDFD00000000ULL,
956 0xFDFDFD0000000000ULL,
957 0xFDFD000000000000ULL,
958 0xFD00000000000000ULL
959 },
960 {
961 0xFDFDFDFDFDFDFDFDULL,
962 0xFDFDFDFDFDFDFDFDULL,
963 0xFDFDFDFDFDFDFD00ULL,
964 0xFDFDFDFDFDFD0000ULL,
965 0xFDFDFDFDFD000000ULL,
966 0xFDFDFDFD00000000ULL,
967 0xFDFDFD0000000000ULL,
968 0xFDFD000000000000ULL
969 },
970 {
971 0xFDFDFDFDFDFDFDFDULL,
972 0xFDFDFDFDFDFDFDFDULL,
973 0xFDFDFDFDFDFDFDFDULL,
974 0xFDFDFDFDFDFDFD00ULL,
975 0xFDFDFDFDFDFD0000ULL,
976 0xFDFDFDFDFD000000ULL,
977 0xFDFDFDFD00000000ULL,
978 0xFDFDFD0000000000ULL
979 },
980 {
981 0xFDFDFDFDFDFDFDFDULL,
982 0xFDFDFDFDFDFDFDFDULL,
983 0xFDFDFDFDFDFDFDFDULL,
984 0xFDFDFDFDFDFDFDFDULL,
985 0xFDFDFDFDFDFDFD00ULL,
986 0xFDFDFDFDFDFD0000ULL,
987 0xFDFDFDFDFD000000ULL,
988 0xFDFDFDFD00000000ULL
989 },
990 {
991 0xFDFDFDFDFDFDFDFDULL,
992 0xFDFDFDFDFDFDFDFDULL,
993 0xFDFDFDFDFDFDFDFDULL,
994 0xFDFDFDFDFDFDFDFDULL,
995 0xFDFDFDFDFDFDFDFDULL,
996 0xFDFDFDFDFDFDFD00ULL,
997 0xFDFDFDFDFDFD0000ULL,
998 0xFDFDFDFDFD000000ULL
999 },
1000 {
1001 0xFDFDFDFDFDFDFDFDULL,
1002 0xFDFDFDFDFDFDFDFDULL,
1003 0xFDFDFDFDFDFDFDFDULL,
1004 0xFDFDFDFDFDFDFDFDULL,
1005 0xFDFDFDFDFDFDFDFDULL,
1006 0xFDFDFDFDFDFDFDFDULL,
1007 0xFDFDFDFDFDFDFD00ULL,
1008 0xFDFDFDFDFDFD0000ULL
1009 },
1010 {
1011 0xFDFDFDFDFDFDFDFDULL,
1012 0xFDFDFDFDFDFDFDFDULL,
1013 0xFDFDFDFDFDFDFDFDULL,
1014 0xFDFDFDFDFDFDFDFDULL,
1015 0xFDFDFDFDFDFDFDFDULL,
1016 0xFDFDFDFDFDFDFDFDULL,
1017 0xFDFDFDFDFDFDFDFDULL,
1018 0xFDFDFDFDFDFDFD00ULL
1019 },
1020 {
1021 0xFDFDFDFDFDFDFDFDULL,
1022 0xFDFDFDFDFDFDFDFDULL,
1023 0xFDFDFDFDFDFDFDFDULL,
1024 0xFDFDFDFDFDFDFDFDULL,
1025 0xFDFDFDFDFDFDFDFDULL,
1026 0xFDFDFDFDFDFDFDFDULL,
1027 0xFDFDFDFDFDFDFDFDULL,
1028 0xFDFDFDFDFDFDFDFDULL
1029 }
1030 },
1031 {
1032 {
1033 0x0000000000000000ULL,
1034 0x0000000000000000ULL,
1035 0x0000000000000000ULL,
1036 0x0000000000000000ULL,
1037 0x0000000000000000ULL,
1038 0x0000000000000000ULL,
1039 0x0000000000000000ULL,
1040 0x0000000000000000ULL
1041 },
1042 {
1043 0x00000000000000FDULL,
1044 0x0000000000000000ULL,
1045 0x0000000000000000ULL,
1046 0x0000000000000000ULL,
1047 0x0000000000000000ULL,
1048 0x0000000000000000ULL,
1049 0x0000000000000000ULL,
1050 0x0000000000000000ULL
1051 },
1052 {
1053 0x000000000000FDFDULL,
1054 0x00000000000000FDULL,
1055 0x0000000000000000ULL,
1056 0x0000000000000000ULL,
1057 0x0000000000000000ULL,
1058 0x0000000000000000ULL,
1059 0x0000000000000000ULL,
1060 0x0000000000000000ULL
1061 },
1062 {
1063 0x0000000000FDFDFDULL,
1064 0x000000000000FDFDULL,
1065 0x00000000000000FDULL,
1066 0x0000000000000000ULL,
1067 0x0000000000000000ULL,
1068 0x0000000000000000ULL,
1069 0x0000000000000000ULL,
1070 0x0000000000000000ULL
1071 },
1072 {
1073 0x00000000FDFDFDFDULL,
1074 0x0000000000FDFDFDULL,
1075 0x000000000000FDFDULL,
1076 0x00000000000000FDULL,
1077 0x0000000000000000ULL,
1078 0x0000000000000000ULL,
1079 0x0000000000000000ULL,
1080 0x0000000000000000ULL
1081 },
1082 {
1083 0x000000FDFDFDFDFDULL,
1084 0x00000000FDFDFDFDULL,
1085 0x0000000000FDFDFDULL,
1086 0x000000000000FDFDULL,
1087 0x00000000000000FDULL,
1088 0x0000000000000000ULL,
1089 0x0000000000000000ULL,
1090 0x0000000000000000ULL
1091 },
1092 {
1093 0x0000FDFDFDFDFDFDULL,
1094 0x000000FDFDFDFDFDULL,
1095 0x00000000FDFDFDFDULL,
1096 0x0000000000FDFDFDULL,
1097 0x000000000000FDFDULL,
1098 0x00000000000000FDULL,
1099 0x0000000000000000ULL,
1100 0x0000000000000000ULL
1101 },
1102 {
1103 0x00FDFDFDFDFDFDFDULL,
1104 0x0000FDFDFDFDFDFDULL,
1105 0x000000FDFDFDFDFDULL,
1106 0x00000000FDFDFDFDULL,
1107 0x0000000000FDFDFDULL,
1108 0x000000000000FDFDULL,
1109 0x00000000000000FDULL,
1110 0x0000000000000000ULL
1111 },
1112 {
1113 0xFDFDFDFDFDFDFDFDULL,
1114 0x00FDFDFDFDFDFDFDULL,
1115 0x0000FDFDFDFDFDFDULL,
1116 0x000000FDFDFDFDFDULL,
1117 0x00000000FDFDFDFDULL,
1118 0x0000000000FDFDFDULL,
1119 0x000000000000FDFDULL,
1120 0x00000000000000FDULL
1121 },
1122 {
1123 0xFDFDFDFDFDFDFDFDULL,
1124 0xFDFDFDFDFDFDFDFDULL,
1125 0x00FDFDFDFDFDFDFDULL,
1126 0x0000FDFDFDFDFDFDULL,
1127 0x000000FDFDFDFDFDULL,
1128 0x00000000FDFDFDFDULL,
1129 0x0000000000FDFDFDULL,
1130 0x000000000000FDFDULL
1131 },
1132 {
1133 0xFDFDFDFDFDFDFDFDULL,
1134 0xFDFDFDFDFDFDFDFDULL,
1135 0xFDFDFDFDFDFDFDFDULL,
1136 0x00FDFDFDFDFDFDFDULL,
1137 0x0000FDFDFDFDFDFDULL,
1138 0x000000FDFDFDFDFDULL,
1139 0x00000000FDFDFDFDULL,
1140 0x0000000000FDFDFDULL
1141 },
1142 {
1143 0xFDFDFDFDFDFDFDFDULL,
1144 0xFDFDFDFDFDFDFDFDULL,
1145 0xFDFDFDFDFDFDFDFDULL,
1146 0xFDFDFDFDFDFDFDFDULL,
1147 0x00FDFDFDFDFDFDFDULL,
1148 0x0000FDFDFDFDFDFDULL,
1149 0x000000FDFDFDFDFDULL,
1150 0x00000000FDFDFDFDULL
1151 },
1152 {
1153 0xFDFDFDFDFDFDFDFDULL,
1154 0xFDFDFDFDFDFDFDFDULL,
1155 0xFDFDFDFDFDFDFDFDULL,
1156 0xFDFDFDFDFDFDFDFDULL,
1157 0xFDFDFDFDFDFDFDFDULL,
1158 0x00FDFDFDFDFDFDFDULL,
1159 0x0000FDFDFDFDFDFDULL,
1160 0x000000FDFDFDFDFDULL
1161 },
1162 {
1163 0xFDFDFDFDFDFDFDFDULL,
1164 0xFDFDFDFDFDFDFDFDULL,
1165 0xFDFDFDFDFDFDFDFDULL,
1166 0xFDFDFDFDFDFDFDFDULL,
1167 0xFDFDFDFDFDFDFDFDULL,
1168 0xFDFDFDFDFDFDFDFDULL,
1169 0x00FDFDFDFDFDFDFDULL,
1170 0x0000FDFDFDFDFDFDULL
1171 },
1172 {
1173 0xFDFDFDFDFDFDFDFDULL,
1174 0xFDFDFDFDFDFDFDFDULL,
1175 0xFDFDFDFDFDFDFDFDULL,
1176 0xFDFDFDFDFDFDFDFDULL,
1177 0xFDFDFDFDFDFDFDFDULL,
1178 0xFDFDFDFDFDFDFDFDULL,
1179 0xFDFDFDFDFDFDFDFDULL,
1180 0x00FDFDFDFDFDFDFDULL
1181 },
1182 {
1183 0xFDFDFDFDFDFDFDFDULL,
1184 0xFDFDFDFDFDFDFDFDULL,
1185 0xFDFDFDFDFDFDFDFDULL,
1186 0xFDFDFDFDFDFDFDFDULL,
1187 0xFDFDFDFDFDFDFDFDULL,
1188 0xFDFDFDFDFDFDFDFDULL,
1189 0xFDFDFDFDFDFDFDFDULL,
1190 0xFDFDFDFDFDFDFDFDULL
1191 }
1192 },
1193 {
1194 {
1195 0x0000000000000000ULL,
1196 0x0000000000000000ULL,
1197 0x0000000000000000ULL,
1198 0x0000000000000000ULL,
1199 0x0000000000000000ULL,
1200 0x0000000000000000ULL,
1201 0x0000000000000000ULL,
1202 0x0000000000000000ULL
1203 },
1204 {
1205 0x0000000000000000ULL,
1206 0x0000000000000000ULL,
1207 0x0000000000000000ULL,
1208 0x0000000000000000ULL,
1209 0x0000000000000000ULL,
1210 0x0000000000000000ULL,
1211 0x0000000000000000ULL,
1212 0xFD00000000000000ULL
1213 },
1214 {
1215 0x0000000000000000ULL,
1216 0x0000000000000000ULL,
1217 0x0000000000000000ULL,
1218 0x0000000000000000ULL,
1219 0x0000000000000000ULL,
1220 0x0000000000000000ULL,
1221 0xFD00000000000000ULL,
1222 0xFDFD000000000000ULL
1223 },
1224 {
1225 0x0000000000000000ULL,
1226 0x0000000000000000ULL,
1227 0x0000000000000000ULL,
1228 0x0000000000000000ULL,
1229 0x0000000000000000ULL,
1230 0xFD00000000000000ULL,
1231 0xFDFD000000000000ULL,
1232 0xFDFDFD0000000000ULL
1233 },
1234 {
1235 0x0000000000000000ULL,
1236 0x0000000000000000ULL,
1237 0x0000000000000000ULL,
1238 0x0000000000000000ULL,
1239 0xFD00000000000000ULL,
1240 0xFDFD000000000000ULL,
1241 0xFDFDFD0000000000ULL,
1242 0xFDFDFDFD00000000ULL
1243 },
1244 {
1245 0x0000000000000000ULL,
1246 0x0000000000000000ULL,
1247 0x0000000000000000ULL,
1248 0xFD00000000000000ULL,
1249 0xFDFD000000000000ULL,
1250 0xFDFDFD0000000000ULL,
1251 0xFDFDFDFD00000000ULL,
1252 0xFDFDFDFDFD000000ULL
1253 },
1254 {
1255 0x0000000000000000ULL,
1256 0x0000000000000000ULL,
1257 0xFD00000000000000ULL,
1258 0xFDFD000000000000ULL,
1259 0xFDFDFD0000000000ULL,
1260 0xFDFDFDFD00000000ULL,
1261 0xFDFDFDFDFD000000ULL,
1262 0xFDFDFDFDFDFD0000ULL
1263 },
1264 {
1265 0x0000000000000000ULL,
1266 0xFD00000000000000ULL,
1267 0xFDFD000000000000ULL,
1268 0xFDFDFD0000000000ULL,
1269 0xFDFDFDFD00000000ULL,
1270 0xFDFDFDFDFD000000ULL,
1271 0xFDFDFDFDFDFD0000ULL,
1272 0xFDFDFDFDFDFDFD00ULL
1273 },
1274 {
1275 0xFD00000000000000ULL,
1276 0xFDFD000000000000ULL,
1277 0xFDFDFD0000000000ULL,
1278 0xFDFDFDFD00000000ULL,
1279 0xFDFDFDFDFD000000ULL,
1280 0xFDFDFDFDFDFD0000ULL,
1281 0xFDFDFDFDFDFDFD00ULL,
1282 0xFDFDFDFDFDFDFDFDULL
1283 },
1284 {
1285 0xFDFD000000000000ULL,
1286 0xFDFDFD0000000000ULL,
1287 0xFDFDFDFD00000000ULL,
1288 0xFDFDFDFDFD000000ULL,
1289 0xFDFDFDFDFDFD0000ULL,
1290 0xFDFDFDFDFDFDFD00ULL,
1291 0xFDFDFDFDFDFDFDFDULL,
1292 0xFDFDFDFDFDFDFDFDULL
1293 },
1294 {
1295 0xFDFDFD0000000000ULL,
1296 0xFDFDFDFD00000000ULL,
1297 0xFDFDFDFDFD000000ULL,
1298 0xFDFDFDFDFDFD0000ULL,
1299 0xFDFDFDFDFDFDFD00ULL,
1300 0xFDFDFDFDFDFDFDFDULL,
1301 0xFDFDFDFDFDFDFDFDULL,
1302 0xFDFDFDFDFDFDFDFDULL
1303 },
1304 {
1305 0xFDFDFDFD00000000ULL,
1306 0xFDFDFDFDFD000000ULL,
1307 0xFDFDFDFDFDFD0000ULL,
1308 0xFDFDFDFDFDFDFD00ULL,
1309 0xFDFDFDFDFDFDFDFDULL,
1310 0xFDFDFDFDFDFDFDFDULL,
1311 0xFDFDFDFDFDFDFDFDULL,
1312 0xFDFDFDFDFDFDFDFDULL
1313 },
1314 {
1315 0xFDFDFDFDFD000000ULL,
1316 0xFDFDFDFDFDFD0000ULL,
1317 0xFDFDFDFDFDFDFD00ULL,
1318 0xFDFDFDFDFDFDFDFDULL,
1319 0xFDFDFDFDFDFDFDFDULL,
1320 0xFDFDFDFDFDFDFDFDULL,
1321 0xFDFDFDFDFDFDFDFDULL,
1322 0xFDFDFDFDFDFDFDFDULL
1323 },
1324 {
1325 0xFDFDFDFDFDFD0000ULL,
1326 0xFDFDFDFDFDFDFD00ULL,
1327 0xFDFDFDFDFDFDFDFDULL,
1328 0xFDFDFDFDFDFDFDFDULL,
1329 0xFDFDFDFDFDFDFDFDULL,
1330 0xFDFDFDFDFDFDFDFDULL,
1331 0xFDFDFDFDFDFDFDFDULL,
1332 0xFDFDFDFDFDFDFDFDULL
1333 },
1334 {
1335 0xFDFDFDFDFDFDFD00ULL,
1336 0xFDFDFDFDFDFDFDFDULL,
1337 0xFDFDFDFDFDFDFDFDULL,
1338 0xFDFDFDFDFDFDFDFDULL,
1339 0xFDFDFDFDFDFDFDFDULL,
1340 0xFDFDFDFDFDFDFDFDULL,
1341 0xFDFDFDFDFDFDFDFDULL,
1342 0xFDFDFDFDFDFDFDFDULL
1343 },
1344 {
1345 0xFDFDFDFDFDFDFDFDULL,
1346 0xFDFDFDFDFDFDFDFDULL,
1347 0xFDFDFDFDFDFDFDFDULL,
1348 0xFDFDFDFDFDFDFDFDULL,
1349 0xFDFDFDFDFDFDFDFDULL,
1350 0xFDFDFDFDFDFDFDFDULL,
1351 0xFDFDFDFDFDFDFDFDULL,
1352 0xFDFDFDFDFDFDFDFDULL
1353 }
1354 },
1355 {
1356 {
1357 0x0000000000000000ULL,
1358 0x0000000000000000ULL,
1359 0x0000000000000000ULL,
1360 0x0000000000000000ULL,
1361 0x0000000000000000ULL,
1362 0x0000000000000000ULL,
1363 0x0000000000000000ULL,
1364 0x0000000000000000ULL
1365 },
1366 {
1367 0x0000000000000000ULL,
1368 0x0000000000000000ULL,
1369 0x0000000000000000ULL,
1370 0x0000000000000000ULL,
1371 0x0000000000000000ULL,
1372 0x0000000000000000ULL,
1373 0x0000000000000000ULL,
1374 0x00000000000000FDULL
1375 },
1376 {
1377 0x0000000000000000ULL,
1378 0x0000000000000000ULL,
1379 0x0000000000000000ULL,
1380 0x0000000000000000ULL,
1381 0x0000000000000000ULL,
1382 0x0000000000000000ULL,
1383 0x00000000000000FDULL,
1384 0x000000000000FDFDULL
1385 },
1386 {
1387 0x0000000000000000ULL,
1388 0x0000000000000000ULL,
1389 0x0000000000000000ULL,
1390 0x0000000000000000ULL,
1391 0x0000000000000000ULL,
1392 0x00000000000000FDULL,
1393 0x000000000000FDFDULL,
1394 0x0000000000FDFDFDULL
1395 },
1396 {
1397 0x0000000000000000ULL,
1398 0x0000000000000000ULL,
1399 0x0000000000000000ULL,
1400 0x0000000000000000ULL,
1401 0x00000000000000FDULL,
1402 0x000000000000FDFDULL,
1403 0x0000000000FDFDFDULL,
1404 0x00000000FDFDFDFDULL
1405 },
1406 {
1407 0x0000000000000000ULL,
1408 0x0000000000000000ULL,
1409 0x0000000000000000ULL,
1410 0x00000000000000FDULL,
1411 0x000000000000FDFDULL,
1412 0x0000000000FDFDFDULL,
1413 0x00000000FDFDFDFDULL,
1414 0x000000FDFDFDFDFDULL
1415 },
1416 {
1417 0x0000000000000000ULL,
1418 0x0000000000000000ULL,
1419 0x00000000000000FDULL,
1420 0x000000000000FDFDULL,
1421 0x0000000000FDFDFDULL,
1422 0x00000000FDFDFDFDULL,
1423 0x000000FDFDFDFDFDULL,
1424 0x0000FDFDFDFDFDFDULL
1425 },
1426 {
1427 0x0000000000000000ULL,
1428 0x00000000000000FDULL,
1429 0x000000000000FDFDULL,
1430 0x0000000000FDFDFDULL,
1431 0x00000000FDFDFDFDULL,
1432 0x000000FDFDFDFDFDULL,
1433 0x0000FDFDFDFDFDFDULL,
1434 0x00FDFDFDFDFDFDFDULL
1435 },
1436 {
1437 0x00000000000000FDULL,
1438 0x000000000000FDFDULL,
1439 0x0000000000FDFDFDULL,
1440 0x00000000FDFDFDFDULL,
1441 0x000000FDFDFDFDFDULL,
1442 0x0000FDFDFDFDFDFDULL,
1443 0x00FDFDFDFDFDFDFDULL,
1444 0xFDFDFDFDFDFDFDFDULL
1445 },
1446 {
1447 0x000000000000FDFDULL,
1448 0x0000000000FDFDFDULL,
1449 0x00000000FDFDFDFDULL,
1450 0x000000FDFDFDFDFDULL,
1451 0x0000FDFDFDFDFDFDULL,
1452 0x00FDFDFDFDFDFDFDULL,
1453 0xFDFDFDFDFDFDFDFDULL,
1454 0xFDFDFDFDFDFDFDFDULL
1455 },
1456 {
1457 0x0000000000FDFDFDULL,
1458 0x00000000FDFDFDFDULL,
1459 0x000000FDFDFDFDFDULL,
1460 0x0000FDFDFDFDFDFDULL,
1461 0x00FDFDFDFDFDFDFDULL,
1462 0xFDFDFDFDFDFDFDFDULL,
1463 0xFDFDFDFDFDFDFDFDULL,
1464 0xFDFDFDFDFDFDFDFDULL
1465 },
1466 {
1467 0x00000000FDFDFDFDULL,
1468 0x000000FDFDFDFDFDULL,
1469 0x0000FDFDFDFDFDFDULL,
1470 0x00FDFDFDFDFDFDFDULL,
1471 0xFDFDFDFDFDFDFDFDULL,
1472 0xFDFDFDFDFDFDFDFDULL,
1473 0xFDFDFDFDFDFDFDFDULL,
1474 0xFDFDFDFDFDFDFDFDULL
1475 },
1476 {
1477 0x000000FDFDFDFDFDULL,
1478 0x0000FDFDFDFDFDFDULL,
1479 0x00FDFDFDFDFDFDFDULL,
1480 0xFDFDFDFDFDFDFDFDULL,
1481 0xFDFDFDFDFDFDFDFDULL,
1482 0xFDFDFDFDFDFDFDFDULL,
1483 0xFDFDFDFDFDFDFDFDULL,
1484 0xFDFDFDFDFDFDFDFDULL
1485 },
1486 {
1487 0x0000FDFDFDFDFDFDULL,
1488 0x00FDFDFDFDFDFDFDULL,
1489 0xFDFDFDFDFDFDFDFDULL,
1490 0xFDFDFDFDFDFDFDFDULL,
1491 0xFDFDFDFDFDFDFDFDULL,
1492 0xFDFDFDFDFDFDFDFDULL,
1493 0xFDFDFDFDFDFDFDFDULL,
1494 0xFDFDFDFDFDFDFDFDULL
1495 },
1496 {
1497 0x00FDFDFDFDFDFDFDULL,
1498 0xFDFDFDFDFDFDFDFDULL,
1499 0xFDFDFDFDFDFDFDFDULL,
1500 0xFDFDFDFDFDFDFDFDULL,
1501 0xFDFDFDFDFDFDFDFDULL,
1502 0xFDFDFDFDFDFDFDFDULL,
1503 0xFDFDFDFDFDFDFDFDULL,
1504 0xFDFDFDFDFDFDFDFDULL
1505 },
1506 {
1507 0xFDFDFDFDFDFDFDFDULL,
1508 0xFDFDFDFDFDFDFDFDULL,
1509 0xFDFDFDFDFDFDFDFDULL,
1510 0xFDFDFDFDFDFDFDFDULL,
1511 0xFDFDFDFDFDFDFDFDULL,
1512 0xFDFDFDFDFDFDFDFDULL,
1513 0xFDFDFDFDFDFDFDFDULL,
1514 0xFDFDFDFDFDFDFDFDULL
1515 }
1516 }
1517 };
1518
1519 static bool is_opening_screen;
1520 int32_t black_opening_count=0;
1521 int32_t black_opening_x,black_opening_y;
1522 int32_t black_opening_shape;
1523
1524 3425 int32_t choose_opening_shape()
1525 {
1526 // First, count how many bits are set
1527 3425 int32_t numBits=0;
1528 int32_t bitCounter;
1529
1530
2/2
✓ Branch 0 taken 17125 times.
✓ Branch 1 taken 3425 times.
20550 for(int32_t i=0; i<bosMAX; i++)
1531 {
1532
2/2
✓ Branch 0 taken 13484 times.
✓ Branch 1 taken 3641 times.
17125 if(COOLSCROLL&(1<<i))
1533 3641 numBits++;
1534 17125 }
1535
1536 // Shouldn't happen...
1537
1/2
✓ Branch 0 taken 3425 times.
✗ Branch 1 not taken.
3425 if(numBits==0)
1538 return bosCIRCLE;
1539
1540 // Pick a bit
1541 3425 bitCounter=zc_rand()%numBits+1;
1542
1543
2/2
✓ Branch 0 taken 4897 times.
✓ Branch 1 taken 26 times.
4923 for(int32_t i=0; i<bosMAX; i++)
1544 {
1545 // If this bit is set, decrement the bit counter
1546
2/2
✓ Branch 0 taken 1342 times.
✓ Branch 1 taken 3555 times.
4897 if(COOLSCROLL&(1<<i))
1547 3555 bitCounter--;
1548
1549 // When the counter hits 0, return a value based on
1550 // which bit it stopped on.
1551 // Reminder: enum {bosCIRCLE=0, bosOVAL, bosTRIANGLE, bosSMAS, bosFADEBLACK, bosMAX};
1552
2/2
✓ Branch 0 taken 3399 times.
✓ Branch 1 taken 1498 times.
4897 if(bitCounter==0)
1553 3399 return i;
1554 1498 }
1555
1556 // Shouldn't be necessary, but the compiler might complain, at least
1557 26 return bosCIRCLE;
1558 3425 }
1559
1560 740 void close_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1561 {
1562 740 x -= viewport.x;
1563 740 y -= viewport.y;
1564
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 730 times.
740 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1565
1566 740 int32_t w=framebuf->w, h=framebuf->h;
1567 740 int32_t blockrows=h/8, blockcolumns=32;
1568 740 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1569
1570
2/2
✓ Branch 0 taken 20721 times.
✓ Branch 1 taken 740 times.
21461 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1571 {
1572
2/2
✓ Branch 0 taken 663072 times.
✓ Branch 1 taken 20721 times.
683793 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1573 {
1574
2/2
✓ Branch 0 taken 274113 times.
✓ Branch 1 taken 388959 times.
663072 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1575 663072 }
1576 20721 }
1577
1578 740 black_opening_count = 66;
1579 740 black_opening_x = x;
1580 740 black_opening_y = y;
1581 740 lensclk = 0;
1582 //black_opening_shape=(black_opening_shape+1)%bosMAX;
1583
1584
1585
1/2
✓ Branch 0 taken 740 times.
✗ Branch 1 not taken.
740 if(black_opening_shape == bosFADEBLACK)
1586 {
1587 refreshTints();
1588 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1589 }
1590
2/2
✓ Branch 0 taken 725 times.
✓ Branch 1 taken 15 times.
740 if(wait)
1591 {
1592 15 FFCore.warpScriptCheck();
1593
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 990 times.
1005 for(int32_t i=0; i<66; i++)
1594 {
1595 990 draw_screen();
1596 990 advanceframe(true);
1597
1598
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 990 times.
990 if(Quit)
1599 {
1600 break;
1601 }
1602 990 }
1603 15 }
1604 740 }
1605
1606 2705 void open_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1607 {
1608 2705 x -= viewport.x;
1609 2705 y -= viewport.y;
1610
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2695 times.
2705 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1611
1612 2705 int32_t w=framebuf->w, h=framebuf->h;
1613 2705 int32_t blockrows=h/8, blockcolumns=32;
1614 2705 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1615
1616
2/2
✓ Branch 0 taken 75993 times.
✓ Branch 1 taken 2705 times.
78698 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1617 {
1618
2/2
✓ Branch 0 taken 2431776 times.
✓ Branch 1 taken 75993 times.
2507769 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1619 {
1620
2/2
✓ Branch 0 taken 1202747 times.
✓ Branch 1 taken 1229029 times.
2431776 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1621 2431776 }
1622 75993 }
1623
1624 2705 black_opening_count = -66;
1625 2705 black_opening_x = x;
1626 2705 black_opening_y = y;
1627 2705 lensclk = 0;
1628
1/2
✓ Branch 0 taken 2705 times.
✗ Branch 1 not taken.
2705 if(black_opening_shape == bosFADEBLACK)
1629 {
1630 refreshTints();
1631 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1632 }
1633
2/2
✓ Branch 0 taken 361 times.
✓ Branch 1 taken 2344 times.
2705 if(wait)
1634 {
1635 2344 FFCore.warpScriptCheck();
1636
2/2
✓ Branch 0 taken 2340 times.
✓ Branch 1 taken 154624 times.
156964 for(int32_t i=0; i<66; i++)
1637 {
1638 154624 draw_screen();
1639 154624 advanceframe(true);
1640
1641
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 154620 times.
154624 if(Quit)
1642 {
1643 4 break;
1644 }
1645 154620 }
1646 2344 }
1647 2705 }
1648
1649 226968 void black_opening(BITMAP *dest,int32_t x,int32_t y,int32_t a,int32_t max_a)
1650 {
1651 226968 clear_to_color(tmp_scr,BLACK);
1652 226968 int32_t w=dest->w, h=dest->h;
1653
1654
4/6
✗ Branch 0 not taken.
✓ Branch 1 taken 9636 times.
✓ Branch 2 taken 10867 times.
✓ Branch 3 taken 20460 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 186005 times.
226968 switch(black_opening_shape)
1655 {
1656 case bosOVAL:
1657 {
1658 9636 double new_w=(w/2)+abs(w/2-x);
1659 9636 double new_h=(h/2)+abs(h/2-y);
1660 9636 double b=sqrt(((new_w*new_w)/4)+(new_h*new_h));
1661 9636 ellipsefill(tmp_scr,x,y,int32_t(2*a*b/max_a)/8*8,int32_t(a*b/max_a)/8*8,0);
1662 9636 break;
1663 }
1664
1665 case bosTRIANGLE:
1666 {
1667 10867 double new_w=(w/2)+abs(w/2-x);
1668 10867 double new_h=(h/2)+abs(h/2-y);
1669 10867 double r=a*(new_w*sqrt((double)3)+new_h)/max_a;
1670 10867 double P2= (PI/2);
1671 10867 double P23=(2*PI/3);
1672 10867 double P43=(4*PI/3);
1673 10867 double Pa= (-4*PI*a/(3*max_a));
1674 10867 double angle=P2+Pa;
1675 10867 double a0=angle;
1676 10867 double a2=angle+P23;
1677 10867 double a4=angle+P43;
1678 21734 triangle(tmp_scr, x+int32_t(zc::math::Cos(a0)*r), y-int32_t(zc::math::Sin(a0)*r),
1679 10867 x+int32_t(zc::math::Cos(a2)*r), y-int32_t(zc::math::Sin(a2)*r),
1680 10867 x+int32_t(zc::math::Cos(a4)*r), y-int32_t(zc::math::Sin(a4)*r),
1681 0);
1682 10867 break;
1683 }
1684
1685 case bosSMAS:
1686 {
1687
2/2
✓ Branch 0 taken 7326 times.
✓ Branch 1 taken 13134 times.
20460 int32_t distance=zc_max(abs(w/2-x),abs(h/2-y))/8;
1688
1689
2/2
✓ Branch 0 taken 572946 times.
✓ Branch 1 taken 20460 times.
593406 for(int32_t blockrow=0; blockrow<h/8; ++blockrow) //30
1690 {
1691
2/2
✓ Branch 0 taken 4583568 times.
✓ Branch 1 taken 572946 times.
5156514 for(int32_t linerow=0; linerow<8; ++linerow)
1692 {
1693 4583568 qword *triangleline=(qword*)(tmp_scr->line[(blockrow*8+linerow)]);
1694
1695
2/2
✓ Branch 0 taken 146674176 times.
✓ Branch 1 taken 4583568 times.
151257744 for(int32_t blockcolumn=0; blockcolumn<32; ++blockcolumn) //40
1696 {
1697 440022528 *triangleline=triangles[(screen_triangles[blockrow][blockcolumn]&0xC000)>>14]
1698
6/6
✓ Branch 0 taken 105995224 times.
✓ Branch 1 taken 40678952 times.
✓ Branch 2 taken 96779136 times.
✓ Branch 3 taken 49895040 times.
✓ Branch 4 taken 56100184 times.
✓ Branch 5 taken 40678952 times.
146674176 [zc_min(zc_max((((31+distance)*(max_a-a)/max_a)+((screen_triangles[blockrow][blockcolumn]&0x0FFF)-0x0100)-(15+distance)),0),15)]
1699 146674176 [linerow];
1700 146674176 ++triangleline;
1701 146674176 }
1702 4583568 }
1703 572946 }
1704
1705 20460 break;
1706 }
1707
1708 case bosFADEBLACK:
1709 {
1710 if(black_opening_count<0)
1711 {
1712 black_fade(zc_min(-black_opening_count,63));
1713 }
1714 else if(black_opening_count>0)
1715 {
1716 black_fade(63-zc_max(black_opening_count-3,0));
1717 }
1718 else black_fade(0);
1719 return; //no blitting from tmp_scr!
1720 }
1721
1722 186005 case bosCIRCLE:
1723 default:
1724 {
1725 186005 double new_w=(w/2)+abs(w/2-x);
1726 186005 double new_h=(h/2)+abs(h/2-y);
1727 186005 int32_t r=int32_t(sqrt((new_w*new_w)+(new_h*new_h))*a/max_a);
1728 //circlefill(tmp_scr,x,y,a<<3,0);
1729 186005 circlefill(tmp_scr,x,y,r,0);
1730 186005 break;
1731 }
1732 }
1733
1734 226968 masked_blit(tmp_scr,dest,0,0,0,0,320,240);
1735 226968 }
1736
1737 // fadeamnt is 0-63
1738 void black_fade(int32_t fadeamnt)
1739 {
1740 fadeamnt = _rgb_scale_6[fadeamnt];
1741 for(int32_t i=0; i < 0xEF; i++)
1742 {
1743 RAMpal[i].r = vbound(tempblackpal[i].r-fadeamnt,0,255);
1744 RAMpal[i].g = vbound(tempblackpal[i].g-fadeamnt,0,255);
1745 RAMpal[i].b = vbound(tempblackpal[i].b-fadeamnt,0,255);
1746 }
1747
1748 refreshpal = true;
1749 }
1750
1751 //----------------------------------------------------------------
1752
1753 208609662 bool item_disabled(int32_t item) //is this item disabled?
1754 {
1755
2/2
✓ Branch 0 taken 15096857 times.
✓ Branch 1 taken 193512805 times.
208609662 return (unsigned(item) < MAXITEMS && game->items_off[item] != 0);
1756 }
1757
1758 16250312 bool can_use_item(int32_t item_type, int32_t item) //can Hero use this item?
1759 {
1760
2/2
✓ Branch 0 taken 261172 times.
✓ Branch 1 taken 15989140 times.
16250312 if(current_item(item_type, true) >=item)
1761 {
1762 261172 return true;
1763 }
1764
1765 15989140 return false;
1766 16250312 }
1767
1768 45721177 bool has_item(int32_t item_type, int32_t it) //does Hero possess this item?
1769 {
1770
5/9
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4628307 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 337472 times.
✓ Branch 6 taken 30471132 times.
✓ Branch 7 taken 10077449 times.
✓ Branch 8 taken 206817 times.
45721177 switch(item_type)
1771 {
1772 case itype_bomb:
1773 case itype_sbomb:
1774 {
1775 int32_t itemid = getItemID(itemsbuf, item_type, it);
1776
1777 if(itemid == -1)
1778 return false;
1779
1780 return (game->get_item(itemid));
1781 }
1782
1783 case itype_clock:
1784 {
1785 4628307 int32_t itemid = getItemID(itemsbuf, item_type, it);
1786
1787
2/4
✓ Branch 0 taken 4628307 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4628307 times.
✗ Branch 3 not taken.
4628307 if(itemid != -1 && (itemsbuf[itemid].flags & item_flag1)) //Active clock
1788 return (game->get_item(itemid));
1789 4628307 return Hero.getClock()?1:0;
1790 }
1791
1792 case itype_key:
1793 return (game->get_keys()>0);
1794
1795 case itype_magiccontainer:
1796 return (game->get_maxmagic()>=game->get_mp_per_block());
1797
1798 case itype_triforcepiece: //it: -2=any, -1=current level, other=that level
1799 {
1800
1/3
✓ Branch 0 taken 337472 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
337472 switch(it)
1801 {
1802 case -2:
1803 {
1804 for(int32_t i=0; i<MAXLEVELS; i++)
1805 {
1806 if(game->lvlitems[i]&(1 << li_mcguffin))
1807 {
1808 return true;
1809 }
1810 }
1811
1812 return false;
1813 }
1814
1815 case -1:
1816 return (game->lvlitems[dlevel]&(1 << li_mcguffin));
1817
1818 default:
1819
2/4
✓ Branch 0 taken 337472 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 337472 times.
337472 if(it>=0&&it<MAXLEVELS)
1820 {
1821 337472 return (game->lvlitems[it]&(1 << li_mcguffin));
1822 }
1823
1824 break;
1825 }
1826
1827 return 0;
1828 }
1829
1830 case itype_map: //it: -2=any, -1=current level, other=that level
1831 {
1832
2/3
✓ Branch 0 taken 541626 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29929506 times.
30471132 switch(it)
1833 {
1834 case -2:
1835 {
1836 for(int32_t i=0; i<MAXLEVELS; i++)
1837 {
1838 if(game->lvlitems[i]&(1 << li_map))
1839 {
1840 return true;
1841 }
1842 }
1843
1844 return false;
1845 }
1846
1847 case -1:
1848 29929506 return (game->lvlitems[dlevel]&(1 << li_map))!=0;
1849
1850 default:
1851
2/4
✓ Branch 0 taken 541626 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 541626 times.
541626 if(it>=0&&it<MAXLEVELS)
1852 {
1853 541626 return (game->lvlitems[it]&(1 << li_map))!=0;
1854 }
1855
1856 break;
1857 }
1858
1859 return 0;
1860 }
1861
1862 case itype_compass: //it: -2=any, -1=current level, other=that level
1863 {
1864
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 10077449 times.
10077449 switch(it)
1865 {
1866 case -2:
1867 {
1868 for(int32_t i=0; i<MAXLEVELS; i++)
1869 {
1870 if(game->lvlitems[i]&(1 << li_compass))
1871 {
1872 return true;
1873 }
1874 }
1875
1876 return false;
1877 }
1878
1879 case -1:
1880 10077449 return (game->lvlitems[dlevel]&(1 << li_compass))!=0;
1881
1882 default:
1883 if(it>=0&&it<MAXLEVELS)
1884 {
1885 return (game->lvlitems[it]&(1 << li_compass))!=0;
1886 }
1887
1888 break;
1889 }
1890 return 0;
1891 }
1892
1893 case itype_bosskey: //it: -2=any, -1=current level, other=that level
1894 {
1895
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 206817 times.
206817 switch(it)
1896 {
1897 case -2:
1898 {
1899 for(int32_t i=0; i<MAXLEVELS; i++)
1900 {
1901 if(game->lvlitems[i]&(1 << li_boss_key))
1902 {
1903 return true;
1904 }
1905 }
1906
1907 return false;
1908 }
1909
1910 case -1:
1911 206817 return (game->lvlitems[dlevel]&(1 << li_boss_key))?1:0;
1912
1913 default:
1914 if(it>=0&&it<MAXLEVELS)
1915 {
1916 return (game->lvlitems[it]&(1 << li_boss_key))?1:0;
1917 }
1918 break;
1919 }
1920 return 0;
1921 }
1922
1923 default:
1924 int32_t itemid = getItemID(itemsbuf, item_type, it);
1925
1926 if(itemid == -1)
1927 return false;
1928
1929 return game->get_item(itemid);
1930 }
1931 45721177 }
1932
1933 157218511 int current_item(int item_type, bool checkmagic, bool jinx_check, bool check_bunny)
1934 {
1935
9/9
✓ Branch 0 taken 4628307 times.
✓ Branch 1 taken 120192055 times.
✓ Branch 2 taken 4628307 times.
✓ Branch 3 taken 4628307 times.
✓ Branch 4 taken 4628307 times.
✓ Branch 5 taken 4628307 times.
✓ Branch 6 taken 4628307 times.
✓ Branch 7 taken 4628307 times.
✓ Branch 8 taken 4628307 times.
157218511 switch(item_type)
1936 {
1937 case itype_clock:
1938 {
1939 4628307 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
1940
1941
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4628307 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4628307 if(maxid != -1 && (itemsbuf[maxid].flags & item_flag1)) //Active clock
1942 return itemsbuf[maxid].level;
1943
1944 4628307 return has_item(itype_clock,1) ? 1 : 0;
1945 }
1946
1947 case itype_key:
1948 4628307 return game->get_keys();
1949
1950 case itype_lkey:
1951 4628307 return game->lvlkeys[get_dlevel()];
1952
1953 case itype_magiccontainer:
1954 4628307 return game->get_maxmagic()/game->get_mp_per_block();
1955
1956 case itype_triforcepiece:
1957 {
1958 4628307 int count=0;
1959
1960
2/2
✓ Branch 0 taken 2369693184 times.
✓ Branch 1 taken 4628307 times.
2374321491 for(int i=0; i<MAXLEVELS; i++)
1961 {
1962 2369693184 count+=(game->lvlitems[i]&(1 << li_mcguffin))?1:0;
1963 2369693184 }
1964
1965 4628307 return count;
1966 }
1967
1968 case itype_map:
1969 {
1970 4628307 int count=0;
1971
1972
2/2
✓ Branch 0 taken 2369693184 times.
✓ Branch 1 taken 4628307 times.
2374321491 for(int i=0; i<MAXLEVELS; i++)
1973 {
1974 2369693184 count+=(game->lvlitems[i]&(1 << li_map))?1:0;
1975 2369693184 }
1976
1977 4628307 return count;
1978 }
1979
1980 case itype_compass:
1981 {
1982 4628307 int count=0;
1983
1984
2/2
✓ Branch 0 taken 2369693184 times.
✓ Branch 1 taken 4628307 times.
2374321491 for(int i=0; i<MAXLEVELS; i++)
1985 {
1986 2369693184 count+=(game->lvlitems[i]&(1 << li_compass))?1:0;
1987 2369693184 }
1988
1989 4628307 return count;
1990 }
1991
1992 case itype_bosskey:
1993 {
1994 4628307 int count=0;
1995
1996
2/2
✓ Branch 0 taken 2369693184 times.
✓ Branch 1 taken 4628307 times.
2374321491 for(int i=0; i<MAXLEVELS; i++)
1997 {
1998 2369693184 count+=(game->lvlitems[i]&(1 << li_boss_key))?1:0;
1999 2369693184 }
2000
2001 4628307 return count;
2002 }
2003
2004 default:
2005 120192055 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
2006
2007
2/2
✓ Branch 0 taken 85819762 times.
✓ Branch 1 taken 34372293 times.
120192055 if(maxid == -1)
2008 85819762 return 0;
2009
2010 34372293 return itemsbuf[maxid].level;
2011 }
2012 157218511 }
2013
2014 429 std::map<int32_t, int32_t> itemcache;
2015 429 std::map<int32_t, int32_t> itemcache_cost;
2016
2017 void removeFromItemCache(int32_t itemclass)
2018 {
2019 itemcache.erase(itemclass);
2020 itemcache_cost.erase(itemclass);
2021 cache_tile_mod_clear();
2022 }
2023
2024 13274030 void flushItemCache(bool justcost)
2025 {
2026 13274030 itemcache_cost.clear();
2027
2/2
✓ Branch 0 taken 13196706 times.
✓ Branch 1 taken 77324 times.
13274030 if(!justcost)
2028 77324 itemcache.clear();
2029
2/2
✓ Branch 0 taken 6357050 times.
✓ Branch 1 taken 6839656 times.
13196706 else if(replay_version_check(0,19))
2030 6357050 return;
2031
2032 6916980 cache_tile_mod_clear();
2033
2034 //also fix the active subscreen if items were deleted -DD
2035
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6916980 times.
6916980 if(game != NULL)
2036 {
2037 6916980 verifyBothWeapons();
2038 6916980 refresh_subscr_items();
2039 6916980 }
2040 13274030 }
2041
2042 // This is used often, so it should be as direct as possible.
2043 3186736692 int _c_item_id_internal(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2044 {
2045 3186736692 bool use_cost_cache = replay_version_check(19);
2046
2/2
✓ Branch 0 taken 3043081906 times.
✓ Branch 1 taken 143654786 times.
3186736692 if(jinx_check)
2047 {
2048 //special case for shields...
2049
3/4
✓ Branch 0 taken 56350838 times.
✓ Branch 1 taken 87303948 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 56350838 times.
143654786 if (itemtype == itype_shield && !HeroShieldClk())
2050 56350838 jinx_check = false;
2051
4/4
✓ Branch 0 taken 54175542 times.
✓ Branch 1 taken 33128406 times.
✓ Branch 2 taken 10934448 times.
✓ Branch 3 taken 43241094 times.
87303948 else if(!(HeroSwordClk() || HeroItemClk()))
2052 43241094 jinx_check = false; //not jinxed
2053 143654786 }
2054
4/4
✓ Branch 0 taken 121490 times.
✓ Branch 1 taken 3186615202 times.
✓ Branch 2 taken 1853 times.
✓ Branch 3 taken 119637 times.
3186736692 if(!Hero.BunnyClock() || itemtype == itype_pearl) // bunny_check does not apply
2055 3186617055 check_bunny = false;
2056
2/2
✓ Branch 0 taken 3126843629 times.
✓ Branch 1 taken 59893063 times.
3186736692 if(itemtype == itype_ring) checkmagic = true;
2057
4/4
✓ Branch 0 taken 3142673838 times.
✓ Branch 1 taken 44062854 times.
✓ Branch 2 taken 309996314 times.
✓ Branch 3 taken 25136236 times.
3521869242 if (!jinx_check && !check_bunny
2058
4/4
✓ Branch 0 taken 3142581809 times.
✓ Branch 1 taken 92029 times.
✓ Branch 2 taken 335132550 times.
✓ Branch 3 taken 2807449259 times.
3142673838 && (use_cost_cache || itemtype != itype_ring))
2059 {
2060
4/4
✓ Branch 0 taken 613245906 times.
✓ Branch 1 taken 2504199667 times.
✓ Branch 2 taken 259612744 times.
✓ Branch 3 taken 353633162 times.
3117445573 auto& cache = checkmagic && use_cost_cache ? itemcache_cost : itemcache;
2061 3117445573 auto res = cache.find(itemtype);
2062
2063
2/2
✓ Branch 0 taken 2960395892 times.
✓ Branch 1 taken 157049681 times.
3117445573 if(res != cache.end())
2064 2960395892 return res->second;
2065 157049681 }
2066
2067 226340800 int result = -1;
2068 226340800 int highestlevel = -1;
2069
2070
2/2
✓ Branch 0 taken 57943244800 times.
✓ Branch 1 taken 226340800 times.
58169585600 for(int i=0; i<MAXITEMS; i++)
2071 {
2072
6/6
✓ Branch 0 taken 6337375300 times.
✓ Branch 1 taken 51605869500 times.
✓ Branch 2 taken 97922665 times.
✓ Branch 3 taken 6239452635 times.
✓ Branch 4 taken 82048 times.
✓ Branch 5 taken 97840617 times.
57943244800 if(game->get_item(i) && itemsbuf[i].type==itemtype && !item_disabled(i))
2073 {
2074
4/4
✓ Branch 0 taken 93081914 times.
✓ Branch 1 taken 4758703 times.
✓ Branch 2 taken 2473495 times.
✓ Branch 3 taken 90608419 times.
97840617 if(checkmagic && itemtype != itype_magicring)
2075
2/2
✓ Branch 0 taken 90604576 times.
✓ Branch 1 taken 3843 times.
90608419 if(!checkmagiccost(i))
2076 3843 continue;
2077
6/6
✓ Branch 0 taken 90348036 times.
✓ Branch 1 taken 7488738 times.
✓ Branch 2 taken 1259368 times.
✓ Branch 3 taken 6229370 times.
✓ Branch 4 taken 4066402 times.
✓ Branch 5 taken 3422336 times.
97836774 if(jinx_check && (usesSwordJinx(i) ? HeroSwordClk() : HeroItemClk()))
2078
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3422336 times.
3422336 if(!(itemsbuf[i].flags & item_jinx_immune))
2079 3422336 continue;
2080
3/4
✓ Branch 0 taken 96967 times.
✓ Branch 1 taken 94317471 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 96967 times.
94414438 if(check_bunny && !checkbunny(i))
2081 96967 continue;
2082
2083
2/2
✓ Branch 0 taken 8703503 times.
✓ Branch 1 taken 85613968 times.
94317471 if(itemsbuf[i].level >= highestlevel)
2084 {
2085 85613968 highestlevel = itemsbuf[i].level;
2086 85613968 result=i;
2087 85613968 }
2088 94317471 }
2089 57939721654 }
2090
2091
4/4
✓ Branch 0 taken 182277946 times.
✓ Branch 1 taken 44062854 times.
✓ Branch 2 taken 92029 times.
✓ Branch 3 taken 182185917 times.
226340800 if(!(jinx_check || check_bunny)) //Can't cache jinx_check/check_bunny
2092 {
2093
2/2
✓ Branch 0 taken 140468871 times.
✓ Branch 1 taken 41717046 times.
182185917 if (use_cost_cache)
2094 {
2095
2/2
✓ Branch 0 taken 122968988 times.
✓ Branch 1 taken 17499883 times.
140468871 if (!checkmagic)
2096 17499883 itemcache[itemtype] = result;
2097
6/6
✓ Branch 0 taken 17499883 times.
✓ Branch 1 taken 122968988 times.
✓ Branch 2 taken 738612 times.
✓ Branch 3 taken 16761271 times.
✓ Branch 4 taken 723464 times.
✓ Branch 5 taken 15148 times.
140468871 if (checkmagic || result < 0 || checkmagiccost(result))
2098 140453723 itemcache_cost[itemtype] = result;
2099 140468871 }
2100 else
2101 {
2102 41717046 itemcache[itemtype] = result;
2103 }
2104 182185917 }
2105 226340800 return result;
2106 3186736692 }
2107
2108 // 'jinx_check' indicates that the highest level item *immune to jinxes* should be returned.
2109 3159978441 int current_item_id(int itype, bool checkmagic, bool jinx_check, bool check_bunny)
2110 {
2111
3/4
✓ Branch 0 taken 3143178202 times.
✓ Branch 1 taken 16800239 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3143178202 times.
3159978441 if(itype < 0 || itype >= itype_max) return -1;
2112
1/2
✓ Branch 0 taken 3143178202 times.
✗ Branch 1 not taken.
3143178202 if(game->OverrideItems[itype] > -2)
2113 {
2114 auto ovid = game->OverrideItems[itype];
2115 if(ovid < 0 || ovid >= MAXITEMS)
2116 return -1;
2117 if(itemsbuf[ovid].type == itype)
2118 {
2119 if(itype == itype_magicring)
2120 checkmagic = false;
2121 else if(itype == itype_ring)
2122 checkmagic = true;
2123
2124 if(checkmagic && !checkmagiccost(ovid))
2125 return -1;
2126
2127 if (jinx_check && !checkitem_jinx(ovid))
2128 {
2129 return -1;
2130 }
2131 return ovid;
2132 }
2133 }
2134 3143178202 auto ret = _c_item_id_internal(itype,checkmagic,jinx_check,check_bunny);
2135
2/2
✓ Branch 0 taken 100096296 times.
✓ Branch 1 taken 3043081906 times.
3143178202 if(!jinx_check) //If not already a jinx-immune-only check...
2136 {
2137 //And the player IS jinxed...
2138
2/2
✓ Branch 0 taken 2999523416 times.
✓ Branch 1 taken 43558490 times.
3043081906 if(HeroIsJinxed())
2139 {
2140 //Then do a jinx-immune-only check here
2141 43558490 auto ret2 = _c_item_id_internal(itype,checkmagic,true,check_bunny);
2142 //And *IF IT FINDS A VALID ITEM*, return that one instead! -Em
2143 //Should NOT need a compat rule, as this should always return -1 in old quests.
2144
2/2
✓ Branch 0 taken 3185185 times.
✓ Branch 1 taken 40373305 times.
43558490 if(ret2 > -1) return ret2;
2145 40373305 }
2146 3039896721 }
2147 3139993017 return ret;
2148 3159978441 }
2149
2150 70661424 int current_item_power(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2151 {
2152 70661424 int result = current_item_id(itemtype, checkmagic, jinx_check, check_bunny);
2153
2/2
✓ Branch 0 taken 37296847 times.
✓ Branch 1 taken 33364577 times.
70661424 return (result<0) ? 0 : itemsbuf[result].power;
2154 }
2155
2156 30 int32_t heart_container_id()
2157 {
2158
1/2
✓ Branch 0 taken 870 times.
✗ Branch 1 not taken.
870 for(int32_t i=0; i<MAXITEMS; i++)
2159 {
2160
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 840 times.
870 if(itemsbuf[i].type == itype_heartcontainer)
2161 {
2162 30 return i;
2163 }
2164 840 }
2165 return -1;
2166 30 }
2167
2168 struct tilemod_cache_state_t
2169 {
2170
6/6
✓ Branch 0 taken 4627951 times.
✓ Branch 1 taken 8980212 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8980210 times.
✓ Branch 4 taken 354 times.
✓ Branch 5 taken 8979856 times.
22588375 bool operator==(const tilemod_cache_state_t&) const = default;
2171
2172 bool valid;
2173 bool bunny_clock;
2174 bool superman;
2175 int shield;
2176 };
2177 tilemod_cache_state_t tilemod_cache_state;
2178 int32_t tilemod_cache_value;
2179
2180 6918581 void cache_tile_mod_clear()
2181 {
2182 6918581 tilemod_cache_state = {false};
2183 6918581 }
2184
2185 13608163 int32_t item_tile_mod()
2186 {
2187 54432652 tilemod_cache_state_t state = {
2188 .valid = true,
2189 13608163 .bunny_clock = Hero.BunnyClock() != 0,
2190 13608163 .superman = Hero.superman,
2191 13608163 .shield = Hero.active_shield_id,
2192 };
2193
2/2
✓ Branch 0 taken 8979856 times.
✓ Branch 1 taken 4628307 times.
13608163 if (tilemod_cache_state == state)
2194 8979856 return tilemod_cache_value;
2195
2196 4628307 int32_t tile=0;
2197 4628307 bool check_bombcost = !get_qr(qr_BROKEN_BOMB_AMMO_COSTS);
2198
4/4
✓ Branch 0 taken 4007945 times.
✓ Branch 1 taken 620362 times.
✓ Branch 2 taken 3079137 times.
✓ Branch 3 taken 928808 times.
4628307 if(check_bombcost || game->get_bombs())
2199 {
2200 3699499 int32_t itemid = current_item_id(itype_bomb,check_bombcost);
2201
3/4
✓ Branch 0 taken 3639623 times.
✓ Branch 1 taken 59876 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3639623 times.
3699499 if(itemid > -1 && checkbunny(itemid))
2202 3639623 tile+=itemsbuf[itemid].ltm;
2203 3699499 }
2204
2205
4/4
✓ Branch 0 taken 4007945 times.
✓ Branch 1 taken 620362 times.
✓ Branch 2 taken 965298 times.
✓ Branch 3 taken 3042647 times.
4628307 if(check_bombcost || game->get_sbombs())
2206 {
2207 1585660 int32_t itemid = current_item_id(itype_sbomb,check_bombcost);
2208
3/4
✓ Branch 0 taken 976704 times.
✓ Branch 1 taken 608956 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 976704 times.
1585660 if(itemid > -1 && checkbunny(itemid))
2209 976704 tile+=itemsbuf[itemid].ltm;
2210 1585660 }
2211
2212
2/2
✓ Branch 0 taken 4615460 times.
✓ Branch 1 taken 12847 times.
4628307 if(current_item(itype_clock))
2213 {
2214 12847 int32_t itemid =
2215
2/2
✓ Branch 0 taken 12702 times.
✓ Branch 1 taken 145 times.
12847 get_qr(qr_HARDCODED_LITEM_LTMS)
2216 ? iClock
2217 145 : getHighestLevelEvenUnowned(itemsbuf, itype_clock);
2218
2/4
✓ Branch 0 taken 12847 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12847 times.
12847 if(itemid > -1 && checkbunny(itemid))
2219 12847 tile+=itemsbuf[itemid].ltm;
2220 12847 }
2221
2222
2/2
✓ Branch 0 taken 3982665 times.
✓ Branch 1 taken 645642 times.
4628307 if(current_item(itype_key))
2223 {
2224 645642 int32_t itemid =
2225
2/2
✓ Branch 0 taken 608640 times.
✓ Branch 1 taken 37002 times.
645642 get_qr(qr_HARDCODED_LITEM_LTMS)
2226 ? iKey
2227 37002 : getHighestLevelEvenUnowned(itemsbuf, itype_key);
2228
2/4
✓ Branch 0 taken 645642 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 645642 times.
645642 if(itemid > -1 && checkbunny(itemid))
2229 645642 tile+=itemsbuf[itemid].ltm;
2230 645642 }
2231
2232
2/2
✓ Branch 0 taken 4070770 times.
✓ Branch 1 taken 557537 times.
4628307 if(current_item(itype_lkey))
2233 {
2234 557537 int32_t itemid =
2235
2/2
✓ Branch 0 taken 414169 times.
✓ Branch 1 taken 143368 times.
557537 get_qr(qr_HARDCODED_LITEM_LTMS)
2236 ? iLevelKey
2237 143368 : getHighestLevelEvenUnowned(itemsbuf, itype_lkey);
2238
2/4
✓ Branch 0 taken 557537 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 557537 times.
557537 if(itemid > -1 && checkbunny(itemid))
2239 557537 tile+=itemsbuf[itemid].ltm;
2240 557537 }
2241
2242
2/2
✓ Branch 0 taken 1586683 times.
✓ Branch 1 taken 3041624 times.
4628307 if(current_item(itype_map))
2243 {
2244 3041624 int32_t itemid =
2245
2/2
✓ Branch 0 taken 2823777 times.
✓ Branch 1 taken 217847 times.
3041624 get_qr(qr_HARDCODED_LITEM_LTMS)
2246 ? iMap
2247 217847 : getHighestLevelEvenUnowned(itemsbuf, itype_map);
2248
2/4
✓ Branch 0 taken 3041624 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3041624 times.
3041624 if(itemid > -1 && checkbunny(itemid))
2249 3041624 tile+=itemsbuf[itemid].ltm;
2250 3041624 }
2251
2252
2/2
✓ Branch 0 taken 2121399 times.
✓ Branch 1 taken 2506908 times.
4628307 if(current_item(itype_compass))
2253 {
2254 2506908 int32_t itemid =
2255
2/2
✓ Branch 0 taken 2295884 times.
✓ Branch 1 taken 211024 times.
2506908 get_qr(qr_HARDCODED_LITEM_LTMS)
2256 ? iCompass
2257 211024 : getHighestLevelEvenUnowned(itemsbuf, itype_compass);
2258
2/4
✓ Branch 0 taken 2506908 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2506908 times.
2506908 if(itemid > -1 && checkbunny(itemid))
2259 2506908 tile+=itemsbuf[itemid].ltm;
2260 2506908 }
2261
2262
2/2
✓ Branch 0 taken 1346996 times.
✓ Branch 1 taken 3281311 times.
4628307 if(current_item(itype_bosskey))
2263 {
2264 3281311 int32_t itemid =
2265
2/2
✓ Branch 0 taken 2993082 times.
✓ Branch 1 taken 288229 times.
3281311 get_qr(qr_HARDCODED_LITEM_LTMS)
2266 ? iBossKey
2267 288229 : getHighestLevelEvenUnowned(itemsbuf, itype_bosskey);
2268
2/4
✓ Branch 0 taken 3281311 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3281311 times.
3281311 if(itemid > -1 && checkbunny(itemid))
2269 3281311 tile+=itemsbuf[itemid].ltm;
2270 3281311 }
2271
2272
2/2
✓ Branch 0 taken 48267 times.
✓ Branch 1 taken 4580040 times.
4628307 if(current_item(itype_magiccontainer))
2273 {
2274 4580040 int32_t itemid =
2275
2/2
✓ Branch 0 taken 3904336 times.
✓ Branch 1 taken 675704 times.
4580040 get_qr(qr_HARDCODED_LITEM_LTMS)
2276 ? iMagicC
2277 675704 : getHighestLevelEvenUnowned(itemsbuf, itype_magiccontainer);
2278
3/4
✓ Branch 0 taken 4580040 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 4580023 times.
4580040 if(itemid > -1 && checkbunny(itemid))
2279 4580023 tile+=itemsbuf[itemid].ltm;
2280 4580040 }
2281
2282
2/2
✓ Branch 0 taken 1329006 times.
✓ Branch 1 taken 3299301 times.
4628307 if(current_item(itype_triforcepiece))
2283 {
2284 3299301 int32_t itemid =
2285
2/2
✓ Branch 0 taken 3069421 times.
✓ Branch 1 taken 229880 times.
3299301 get_qr(qr_HARDCODED_LITEM_LTMS)
2286 ? iTriforce
2287 229880 : getHighestLevelEvenUnowned(itemsbuf, itype_triforcepiece);
2288
2/4
✓ Branch 0 taken 3299301 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3299301 times.
3299301 if(itemid > -1 && checkbunny(itemid))
2289 3299301 tile+=itemsbuf[itemid].ltm;
2290 3299301 }
2291
2292
2/2
✓ Branch 0 taken 2369693184 times.
✓ Branch 1 taken 4628307 times.
2374321491 for(int32_t i=0; i<itype_max; i++)
2293 {
2294
2/2
✓ Branch 0 taken 2023599616 times.
✓ Branch 1 taken 346093568 times.
2369693184 if(!get_qr(qr_HARDCODED_LITEM_LTMS))
2295 {
2296
2/2
✓ Branch 0 taken 6759640 times.
✓ Branch 1 taken 339333928 times.
346093568 switch(i)
2297 {
2298 case itype_bomb:
2299 case itype_sbomb:
2300 case itype_clock:
2301 case itype_key:
2302 case itype_lkey:
2303 case itype_map:
2304 case itype_compass:
2305 case itype_bosskey:
2306 case itype_magiccontainer:
2307 case itype_triforcepiece:
2308 6759640 continue; //already handled
2309 }
2310 339333928 }
2311 2362933544 int32_t itemid = current_item_id(i,false);
2312
2/2
✓ Branch 0 taken 2358305237 times.
✓ Branch 1 taken 4628307 times.
2362933544 if(i == itype_shield)
2313 4628307 itemid = getCurrentShield(false);
2314
2315
4/4
✓ Branch 0 taken 119496932 times.
✓ Branch 1 taken 2243436612 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 119496931 times.
2362933544 if(itemid < 0 || !checkbunny(itemid))
2316 2243436613 continue;
2317
2318 119496931 itemdata const& itm = itemsbuf[itemid];
2319
2320
2/2
✓ Branch 0 taken 115589966 times.
✓ Branch 1 taken 3906965 times.
119496931 switch(itm.type)
2321 {
2322 case itype_shield:
2323
1/2
✓ Branch 0 taken 3906965 times.
✗ Branch 1 not taken.
3906965 if(itm.flags & item_flag9) //active shield
2324 {
2325 if(!usingActiveShield(itemid))
2326 {
2327 tile+=itm.misc6; //'Inactive PTM'
2328 continue;
2329 }
2330 }
2331 3906965 break;
2332 }
2333
2334 119496931 tile+=itm.ltm;
2335 119496931 }
2336
2337 4628307 tilemod_cache_value = tile;
2338 4628307 tilemod_cache_state = state;
2339 4628307 return tile;
2340 13608163 }
2341
2342 13608163 int32_t bunny_tile_mod()
2343 {
2344
2/2
✓ Branch 0 taken 1870 times.
✓ Branch 1 taken 13606293 times.
13608163 if(Hero.BunnyClock())
2345 {
2346 1870 return game->get_bunny_ltm();
2347 }
2348 13606293 return 0;
2349 13608163 }
2350
2351 // Hints are drawn on a separate layer to combo reveals.
2352 // TODO: move out of zc_sys.cpp, weird place for this code.
2353 20058 void draw_lens_under(BITMAP *dest, bool layer)
2354 {
2355 //Lens flag 1: Replacement for qr_LENSHINTS; if set, lens will show hints. Does nothing if flag 2 is set.
2356 //Lens flag 2: Disable "hints", prevent rendering of Secret Combos
2357 //Lens flag 3: Don't show armos/chest/dive items
2358 //Lens flag 4: Show Raft Paths
2359 //Lens flag 5: Show Invisible Enemies
2360
4/4
✓ Branch 0 taken 19602 times.
✓ Branch 1 taken 456 times.
✓ Branch 2 taken 9801 times.
✓ Branch 3 taken 9801 times.
20058 bool hints = (itemsbuf[Hero.getLastLensID()].flags & item_flag2) ? false : (layer && (itemsbuf[Hero.getLastLensID()].flags & item_flag1));
2361
2362 20058 int32_t strike_hint_table[11]=
2363 {
2364 mfARROW, mfBOMB, mfBRANG, mfWANDMAGIC,
2365 mfSWORD, mfREFMAGIC, mfHOOKSHOT,
2366 mfREFFIREBALL, mfHAMMER, mfSWORDBEAM, mfWAND
2367 };
2368
2369 {
2370 20058 int32_t blink_rate=flash_reduction_enabled()?6:1;
2371 20058 int32_t tempitem, tempweapon=0;
2372 20058 strike_hint=strike_hint_table[strike_hint_counter];
2373
2374
2/2
✓ Branch 0 taken 19459 times.
✓ Branch 1 taken 599 times.
20058 if(strike_hint_timer>32)
2375 {
2376 599 strike_hint_timer=0;
2377 599 strike_hint_counter=((strike_hint_counter+1)%11);
2378 599 }
2379
2380 20058 ++strike_hint_timer;
2381
2382 3550266 for_every_visible_rpos_layer0([&](const rpos_handle_t& rpos_handle) {
2383 3530208 mapscr* scr = rpos_handle.scr;
2384 7306676 auto [x, y] = rpos_handle.xy();
2385 7060416 y += playing_field_offset;
2386
2387 3530208 int32_t tempitemx=-16, tempitemy=-16;
2388 3530208 int32_t tempweaponx=-16, tempweapony=-16;
2389
2390
2/2
✓ Branch 0 taken 7060416 times.
✓ Branch 1 taken 3530208 times.
10590624 for(int32_t iter=0; iter<2; ++iter)
2391 {
2392 7060416 int32_t checkflag=0;
2393
2394
2/2
✓ Branch 0 taken 3530208 times.
✓ Branch 1 taken 3530208 times.
7060416 if(iter==0)
2395 {
2396 3530208 checkflag = rpos_handle.cflag();
2397 3530208 }
2398 else
2399 {
2400 3530208 checkflag = rpos_handle.sflag();
2401 }
2402
2403
2/2
✓ Branch 0 taken 7059318 times.
✓ Branch 1 taken 1098 times.
7060416 if(checkflag==mfSTRIKE)
2404 {
2405
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 906 times.
1098 if(!hints)
2406 {
2407
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSTRIKE],scr->secretcset[sSTRIKE]);
2408 906 }
2409 else
2410 {
2411 192 checkflag = strike_hint;
2412 }
2413 1098 }
2414
2415
21/36
✓ Branch 0 taken 6911766 times.
✓ Branch 1 taken 3258 times.
✓ Branch 2 taken 108898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2602 times.
✓ Branch 5 taken 28750 times.
✓ Branch 6 taken 2418 times.
✓ Branch 7 taken 504 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 814 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 93 times.
✓ Branch 15 taken 96 times.
✓ Branch 16 taken 24 times.
✓ Branch 17 taken 25 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 138 times.
✓ Branch 21 taken 16 times.
✓ Branch 22 taken 16 times.
✓ Branch 23 taken 7 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 16 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 17 times.
✓ Branch 32 taken 35 times.
✓ Branch 33 taken 17 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 906 times.
7060416 switch(checkflag)
2416 {
2417 case 0:
2418 case mfZELDA:
2419 case mfPUSHED:
2420 case mfENEMY0:
2421 case mfENEMY1:
2422 case mfENEMY2:
2423 case mfENEMY3:
2424 case mfENEMY4:
2425 case mfENEMY5:
2426 case mfENEMY6:
2427 case mfENEMY7:
2428 case mfENEMY8:
2429 case mfENEMY9:
2430 case mfSINGLE:
2431 case mfSINGLE16:
2432 case mfNOENEMY:
2433 case mfTRAP_H:
2434 case mfTRAP_V:
2435 case mfTRAP_4:
2436 case mfTRAP_LR:
2437 case mfTRAP_UD:
2438 case mfNOGROUNDENEMY:
2439 case mfNOBLOCKS:
2440 case mfSCRIPT1:
2441 case mfSCRIPT2:
2442 case mfSCRIPT3:
2443 case mfSCRIPT4:
2444 case mfSCRIPT5:
2445 case mfSCRIPT6:
2446 case mfSCRIPT7:
2447 case mfSCRIPT8:
2448 case mfSCRIPT9:
2449 case mfSCRIPT10:
2450 case mfSCRIPT11:
2451 case mfSCRIPT12:
2452 case mfSCRIPT13:
2453 case mfSCRIPT14:
2454 case mfSCRIPT15:
2455 case mfSCRIPT16:
2456 case mfSCRIPT17:
2457 case mfSCRIPT18:
2458 case mfSCRIPT19:
2459 case mfSCRIPT20:
2460 case mfPITHOLE:
2461 case mfPITFALLFLOOR:
2462 case mfLAVA:
2463 case mfICE:
2464 case mfICEDAMAGE:
2465 case mfDAMAGE1:
2466 case mfDAMAGE2:
2467 case mfDAMAGE4:
2468 case mfDAMAGE8:
2469 case mfDAMAGE16:
2470 case mfDAMAGE32:
2471 case mfFREEZEALL:
2472 case mfFREZEALLANSFFCS:
2473 case mfFREEZEFFCSOLY:
2474 case mfSCRITPTW1TRIG:
2475 case mfSCRITPTW2TRIG:
2476 case mfSCRITPTW3TRIG:
2477 case mfSCRITPTW4TRIG:
2478 case mfSCRITPTW5TRIG:
2479 case mfSCRITPTW6TRIG:
2480 case mfSCRITPTW7TRIG:
2481 case mfSCRITPTW8TRIG:
2482 case mfSCRITPTW9TRIG:
2483 case mfSCRITPTW10TRIG:
2484 case mfTROWEL:
2485 case mfTROWELNEXT:
2486 case mfTROWELSPECIALITEM:
2487 case mfSLASHPOT:
2488 case mfLIFTPOT:
2489 case mfLIFTORSLASH:
2490 case mfLIFTROCK:
2491 case mfLIFTROCKHEAVY:
2492 case mfDROPITEM:
2493 case mfSPECIALITEM:
2494 case mfDROPKEY:
2495 case mfDROPLKEY:
2496 case mfDROPCOMPASS:
2497 case mfDROPMAP:
2498 case mfDROPBOSSKEY:
2499 case mfSPAWNNPC:
2500 case mfSWITCHHOOK:
2501 case mfSIDEVIEWLADDER:
2502 case mfSIDEVIEWPLATFORM:
2503 case mfNOENEMYSPAWN:
2504 case mfENEMYALL:
2505 case mfNOMIRROR:
2506 case mfUNSAFEGROUND:
2507 case mf168:
2508 case mf169:
2509 case mf170:
2510 case mf171:
2511 case mf172:
2512 case mf173:
2513 case mf174:
2514 case mf175:
2515 case mf176:
2516 case mf177:
2517 case mf178:
2518 case mf179:
2519 case mf180:
2520 case mf181:
2521 case mf182:
2522 case mf183:
2523 case mf184:
2524 case mf185:
2525 case mf186:
2526 case mf187:
2527 case mf188:
2528 case mf189:
2529 case mf190:
2530 case mf191:
2531 case mf192:
2532 case mf193:
2533 case mf194:
2534 case mf195:
2535 case mf196:
2536 case mf197:
2537 case mf198:
2538 case mf199:
2539 case mf200:
2540 case mf201:
2541 case mf202:
2542 case mf203:
2543 case mf204:
2544 case mf205:
2545 case mf206:
2546 case mf207:
2547 case mf208:
2548 case mf209:
2549 case mf210:
2550 case mf211:
2551 case mf212:
2552 case mf213:
2553 case mf214:
2554 case mf215:
2555 case mf216:
2556 case mf217:
2557 case mf218:
2558 case mf219:
2559 case mf220:
2560 case mf221:
2561 case mf222:
2562 case mf223:
2563 case mf224:
2564 case mf225:
2565 case mf226:
2566 case mf227:
2567 case mf228:
2568 case mf229:
2569 case mf230:
2570 case mf231:
2571 case mf232:
2572 case mf233:
2573 case mf234:
2574 case mf235:
2575 case mf236:
2576 case mf237:
2577 case mf238:
2578 case mf239:
2579 case mf240:
2580 case mf241:
2581 case mf242:
2582 case mf243:
2583 case mf244:
2584 case mf245:
2585 case mf246:
2586 case mf247:
2587 case mf248:
2588 case mf249:
2589 case mf250:
2590 case mf251:
2591 case mf252:
2592 case mf253:
2593 case mf254:
2594 case mfEXTENDED:
2595 6911766 break;
2596
2597 case mfPUSHUD:
2598 case mfPUSHLR:
2599 case mfPUSH4:
2600 case mfPUSHU:
2601 case mfPUSHD:
2602 case mfPUSHL:
2603 case mfPUSHR:
2604 case mfPUSHUDNS:
2605 case mfPUSHLRNS:
2606 case mfPUSH4NS:
2607 case mfPUSHUNS:
2608 case mfPUSHDNS:
2609 case mfPUSHLNS:
2610 case mfPUSHRNS:
2611 case mfPUSHUDINS:
2612 case mfPUSHLRINS:
2613 case mfPUSH4INS:
2614 case mfPUSHUINS:
2615 case mfPUSHDINS:
2616 case mfPUSHLINS:
2617 case mfPUSHRINS:
2618
3/4
✓ Branch 0 taken 1939 times.
✓ Branch 1 taken 1319 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
3258 if(!hints && ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&16))
2619
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1939 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1939 || ((get_debug() && zc_getkey(KEY_N)) && (frame&16))))
2620 {
2621 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->undercombo,scr->undercset);
2622 }
2623
2624
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3258 times.
3258 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2625
3/6
✓ Branch 0 taken 2520 times.
✓ Branch 1 taken 738 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 738 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
3258 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2626 {
2627
2/2
✓ Branch 0 taken 1488 times.
✓ Branch 1 taken 1032 times.
2520 if(hints)
2628 {
2629
3/3
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 63 times.
✓ Branch 2 taken 897 times.
1032 switch (rpos_handle.ctype())
2630 {
2631 case cPUSH_HEAVY:
2632 case cPUSH_HW:
2633 72 tempitem=getItemIDPower(itemsbuf,itype_bracelet,1);
2634 144 tempitemx=x, tempitemy=y;
2635
2636
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(tempitem>-1)
2637 72 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2638
2639 72 break;
2640
2641 case cPUSH_HEAVY2:
2642 case cPUSH_HW2:
2643 63 tempitem=getItemIDPower(itemsbuf,itype_bracelet,2);
2644 126 tempitemx=x, tempitemy=y;
2645
2646
1/2
✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
63 if(tempitem>-1)
2647 63 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2648
2649 63 break;
2650 }
2651 1032 }
2652 2520 }
2653
2654 3258 break;
2655
2656 case mfWHISTLE:
2657
1/2
✓ Branch 0 taken 2418 times.
✗ Branch 1 not taken.
2418 if(hints)
2658 {
2659 tempitem=getItemID(itemsbuf,itype_whistle,1);
2660
2661 if(tempitem<0) break;
2662
2663 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2664 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2665 {
2666 tempitemx=x;
2667 tempitemy=y;
2668 }
2669
2670 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2671 }
2672
2673 2418 break;
2674
2675 //Why is this here?
2676 case mfFAIRY:
2677 case mfMAGICFAIRY:
2678 case mfALLFAIRY:
2679 if(hints)
2680 {
2681 tempitem=getItemID(itemsbuf, itype_fairy,1);//iFairyMoving;
2682
2683 if(tempitem < 0) break;
2684
2685 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2686 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2687 {
2688 tempitemx=x;
2689 tempitemy=y;
2690 }
2691
2692 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2693 }
2694
2695 break;
2696
2697 case mfANYFIRE:
2698
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 252 times.
504 if(!hints)
2699 {
2700
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sBCANDLE],scr->secretcset[sBCANDLE]);
2701 252 }
2702 else
2703 {
2704 252 tempitem=getItemID(itemsbuf,itype_candle,1);
2705
2706
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(tempitem<0) break;
2707
2708
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2709
3/6
✓ Branch 0 taken 189 times.
✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 63 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
252 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2710 {
2711 189 tempitemx=x;
2712 189 tempitemy=y;
2713 189 }
2714
2715 252 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2716 }
2717
2718 504 break;
2719
2720 case mfSTRONGFIRE:
2721 if(!hints)
2722 {
2723 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sRCANDLE],scr->secretcset[sRCANDLE]);
2724 }
2725 else
2726 {
2727 tempitem=getItemID(itemsbuf,itype_candle,2);
2728
2729 if(tempitem<0) break;
2730
2731 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2732 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2733 {
2734 tempitemx=x;
2735 tempitemy=y;
2736 }
2737
2738 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2739 }
2740
2741 break;
2742
2743 case mfMAGICFIRE:
2744 if(!hints)
2745 {
2746 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWANDFIRE],scr->secretcset[sWANDFIRE]);
2747 }
2748 else
2749 {
2750 tempitem=getItemID(itemsbuf,itype_wand,1);
2751
2752 if(tempitem<0) break;
2753
2754 tempweapon=wFire;
2755
2756 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2757 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2758 {
2759 tempitemx=x;
2760 tempitemy=y;
2761 }
2762 else
2763 {
2764 tempweaponx=x;
2765 tempweapony=y;
2766 }
2767
2768 putweapon(dest,tempweaponx,tempweapony,tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2769 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2770 }
2771
2772 break;
2773
2774 case mfDIVINEFIRE:
2775 if(!hints)
2776 {
2777 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sDIVINEFIRE],scr->secretcset[sDIVINEFIRE]);
2778 }
2779 else
2780 {
2781 tempitem=getItemID(itemsbuf,itype_divinefire,1);
2782
2783 if(tempitem<0) break;
2784
2785 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2786 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2787 {
2788 tempitemx=x;
2789 tempitemy=y;
2790 }
2791
2792 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2793 }
2794
2795 break;
2796
2797 case mfARROW:
2798
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 732 times.
814 if(!hints)
2799 {
2800
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 732 times.
732 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sARROW],scr->secretcset[sARROW]);
2801 732 }
2802 else
2803 {
2804 82 tempitem=getItemID(itemsbuf,itype_arrow,1);
2805
2806
1/2
✓ Branch 0 taken 82 times.
✗ Branch 1 not taken.
82 if(tempitem<0) break;
2807
2808
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82 times.
82 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2809
3/6
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
82 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2810 {
2811 61 tempitemx=x;
2812 61 tempitemy=y;
2813 61 }
2814
2815 82 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2816 }
2817
2818 814 break;
2819
2820 case mfSARROW:
2821 if(!hints)
2822 {
2823 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSARROW],scr->secretcset[sSARROW]);
2824 }
2825 else
2826 {
2827 tempitem=getItemID(itemsbuf,itype_arrow,2);
2828
2829 if(tempitem<0) break;
2830
2831 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2832 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2833 {
2834 tempitemx=x;
2835 tempitemy=y;
2836 }
2837
2838 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2839 }
2840
2841 break;
2842
2843 case mfGARROW:
2844 if(!hints)
2845 {
2846 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sGARROW],scr->secretcset[sGARROW]);
2847 }
2848 else
2849 {
2850 tempitem=getItemID(itemsbuf,itype_arrow,3);
2851
2852 if(tempitem<0) break;
2853
2854 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2855 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2856 {
2857 tempitemx=x;
2858 tempitemy=y;
2859 }
2860
2861 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2862 }
2863
2864 break;
2865
2866 case mfBOMB:
2867
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 76 times.
93 if(!hints)
2868 {
2869
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
76 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sBOMB],scr->secretcset[sBOMB]);
2870 76 }
2871 else
2872 {
2873 //tempitem=getItemID(itemsbuf,itype_bomb,1);
2874 17 tempweapon = wLitBomb;
2875
2876 //if (tempitem<0) break;
2877
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2878
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2879 {
2880 12 tempweaponx=x;
2881 12 tempweapony=y;
2882 12 }
2883
2884 17 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2885 }
2886
2887 93 break;
2888
2889 case mfSBOMB:
2890
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 48 times.
96 if(!hints)
2891 {
2892
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSBOMB],scr->secretcset[sSBOMB]);
2893 48 }
2894 else
2895 {
2896 //tempitem=getItemID(itemsbuf,itype_sbomb,1);
2897 //if (tempitem<0) break;
2898 48 tempweapon = wLitSBomb;
2899
2900
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2901
3/6
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2902 {
2903 36 tempweaponx=x;
2904 36 tempweapony=y;
2905 36 }
2906
2907 48 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2908 }
2909
2910 96 break;
2911
2912 case mfARMOS_SECRET:
2913
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 if(!hints)
2914 {
2915
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
2916 36 putcombo(dest,x,y,scr->secretcombo[sSTAIRS],scr->secretcset[sSTAIRS]);
2917 12 }
2918 24 break;
2919
2920 case mfBRANG:
2921
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 20 times.
25 if(!hints)
2922 {
2923
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
2924 60 putcombo(dest,x,y,scr->secretcombo[sBRANG],scr->secretcset[sBRANG]);
2925 20 }
2926 else
2927 {
2928 5 tempitem=getItemID(itemsbuf,itype_brang,1);
2929
2930
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(tempitem<0) break;
2931
2932
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2933
3/6
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
5 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2934 {
2935 4 tempitemx=x;
2936 4 tempitemy=y;
2937 4 }
2938
2939 5 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2940 }
2941
2942 25 break;
2943
2944 case mfMBRANG:
2945 if(!hints)
2946 {
2947 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMBRANG],scr->secretcset[sMBRANG]);
2948 }
2949 else
2950 {
2951 tempitem=getItemID(itemsbuf,itype_brang,2);
2952
2953 if(tempitem<0) break;
2954
2955 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2956 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2957 {
2958 tempitemx=x;
2959 tempitemy=y;
2960 }
2961
2962 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2963 }
2964
2965 break;
2966
2967 case mfFBRANG:
2968 if(!hints)
2969 {
2970 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sFBRANG],scr->secretcset[sFBRANG]);
2971 }
2972 else
2973 {
2974 tempitem=getItemID(itemsbuf,itype_brang,3);
2975
2976 if(tempitem<0) break;
2977
2978 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2979 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2980 {
2981 tempitemx=x;
2982 tempitemy=y;
2983 }
2984
2985 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2986 }
2987
2988 break;
2989
2990 case mfWANDMAGIC:
2991
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!hints)
2992 {
2993
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWANDMAGIC],scr->secretcset[sWANDMAGIC]);
2994 138 }
2995 else
2996 {
2997 tempitem=getItemID(itemsbuf,itype_wand,1);
2998
2999 if(tempitem<0) break;
3000
3001 tempweapon=itemsbuf[tempitem].wpn3;
3002
3003 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3004 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3005 {
3006 tempitemx=x;
3007 tempitemy=y;
3008 }
3009 else
3010 {
3011 tempweaponx=x;
3012 tempweapony=y;
3013 --lens_hint_weapon[wMagic][4];
3014
3015 if(lens_hint_weapon[wMagic][4]<-8)
3016 {
3017 lens_hint_weapon[wMagic][4]=8;
3018 }
3019 }
3020
3021 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3022 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3023 }
3024
3025 138 break;
3026
3027 case mfREFMAGIC:
3028
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3029 {
3030 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sREFMAGIC],scr->secretcset[sREFMAGIC]);
3031 }
3032 else
3033 {
3034 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3035
3036
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3037
3038 16 tempweapon=ewMagic;
3039
3040
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3041
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3042 {
3043 13 tempitemx=x;
3044 13 tempitemy=y;
3045 13 }
3046 else
3047 {
3048 3 tempweaponx=x;
3049 3 tempweapony=y;
3050
3051
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if(lens_hint_weapon[ewMagic][2]==up)
3052 {
3053 1 --lens_hint_weapon[ewMagic][4];
3054 1 }
3055 else
3056 {
3057 2 ++lens_hint_weapon[ewMagic][4];
3058 }
3059
3060
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(lens_hint_weapon[ewMagic][4]>8)
3061 {
3062 lens_hint_weapon[ewMagic][2]=up;
3063 }
3064
3065
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if(lens_hint_weapon[ewMagic][4]<=0)
3066 {
3067 2 lens_hint_weapon[ewMagic][2]=down;
3068 2 }
3069 }
3070
3071 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3072 16 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, lens_hint_weapon[ewMagic][2], lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3073 }
3074
3075 16 break;
3076
3077 case mfREFFIREBALL:
3078
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3079 {
3080 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sREFFIREBALL],scr->secretcset[sREFFIREBALL]);
3081 }
3082 else
3083 {
3084 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3085
3086
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3087
3088 16 tempweapon=ewFireball;
3089
3090
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3091
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3092 {
3093 12 tempitemx=x;
3094 12 tempitemy=y;
3095 12 tempweaponx=x;
3096 12 tempweapony=y;
3097 12 ++lens_hint_weapon[ewFireball][3];
3098
3099
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
12 if(lens_hint_weapon[ewFireball][3]>8)
3100 {
3101 1 lens_hint_weapon[ewFireball][3]=-8;
3102 1 lens_hint_weapon[ewFireball][4]=8;
3103 1 }
3104
3105
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 if(lens_hint_weapon[ewFireball][3]>0)
3106 {
3107 8 ++lens_hint_weapon[ewFireball][4];
3108 8 }
3109 else
3110 {
3111 4 --lens_hint_weapon[ewFireball][4];
3112 }
3113 12 }
3114
3115 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3116 16 putweapon(dest,tempweaponx+lens_hint_weapon[tempweapon][3],tempweapony+lens_hint_weapon[ewFireball][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3117 }
3118
3119 16 break;
3120
3121 case mfSWORD:
3122
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(!hints)
3123 {
3124 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSWORD],scr->secretcset[sSWORD]);
3125 }
3126 else
3127 {
3128 7 tempitem=getItemID(itemsbuf,itype_sword,1);
3129
3130
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(tempitem<0) break;
3131
3132
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3133
3/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
7 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3134 {
3135 5 tempitemx=x;
3136 5 tempitemy=y;
3137 5 }
3138
3139 7 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3140 }
3141
3142 7 break;
3143
3144 case mfWSWORD:
3145 if(!hints)
3146 {
3147 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWSWORD],scr->secretcset[sWSWORD]);
3148 }
3149 else
3150 {
3151 tempitem=getItemID(itemsbuf,itype_sword,2);
3152
3153 if(tempitem<0) break;
3154
3155 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3156 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3157 {
3158 tempitemx=x;
3159 tempitemy=y;
3160 }
3161
3162 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3163 }
3164
3165 break;
3166
3167 case mfMSWORD:
3168 if(!hints)
3169 {
3170 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMSWORD],scr->secretcset[sMSWORD]);
3171 }
3172 else
3173 {
3174 tempitem=getItemID(itemsbuf,itype_sword,3);
3175
3176 if(tempitem<0) break;
3177
3178 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3179 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3180 {
3181 tempitemx=x;
3182 tempitemy=y;
3183 }
3184
3185 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3186 }
3187
3188 break;
3189
3190 case mfXSWORD:
3191 if(!hints)
3192 {
3193 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sXSWORD],scr->secretcset[sXSWORD]);
3194 }
3195 else
3196 {
3197 tempitem=getItemID(itemsbuf,itype_sword,4);
3198
3199 if(tempitem<0) break;
3200
3201 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3202 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3203 {
3204 tempitemx=x;
3205 tempitemy=y;
3206 }
3207
3208 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3209 }
3210
3211 break;
3212
3213 case mfSWORDBEAM:
3214
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3215 {
3216 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSWORDBEAM],scr->secretcset[sSWORDBEAM]);
3217 }
3218 else
3219 {
3220 16 tempitem=getItemID(itemsbuf,itype_sword,1);
3221
3222
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3223
3224
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3225
3/6
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3226 {
3227 11 tempitemx=x;
3228 11 tempitemy=y;
3229 11 }
3230
3231 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 1);
3232 }
3233
3234 16 break;
3235
3236 case mfWSWORDBEAM:
3237 if(!hints)
3238 {
3239 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWSWORDBEAM],scr->secretcset[sWSWORDBEAM]);
3240 }
3241 else
3242 {
3243 tempitem=getItemID(itemsbuf,itype_sword,2);
3244
3245 if(tempitem<0) break;
3246
3247 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3248 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3249 {
3250 tempitemx=x;
3251 tempitemy=y;
3252 }
3253
3254 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 2);
3255 }
3256
3257 break;
3258
3259 case mfMSWORDBEAM:
3260 if(!hints)
3261 {
3262 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMSWORDBEAM],scr->secretcset[sMSWORDBEAM]);
3263 }
3264 else
3265 {
3266 tempitem=getItemID(itemsbuf,itype_sword,3);
3267
3268 if(tempitem<0) break;
3269
3270 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3271 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3272 {
3273 tempitemx=x;
3274 tempitemy=y;
3275 }
3276
3277 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 3);
3278 }
3279
3280 break;
3281
3282 case mfXSWORDBEAM:
3283 if(!hints)
3284 {
3285 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sXSWORDBEAM],scr->secretcset[sXSWORDBEAM]);
3286 }
3287 else
3288 {
3289 tempitem=getItemID(itemsbuf,itype_sword,4);
3290
3291 if(tempitem<0) break;
3292
3293 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3294 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3295 {
3296 tempitemx=x;
3297 tempitemy=y;
3298 }
3299
3300 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 4);
3301 }
3302
3303 break;
3304
3305 case mfHOOKSHOT:
3306
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3307 {
3308 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sHOOKSHOT],scr->secretcset[sHOOKSHOT]);
3309 }
3310 else
3311 {
3312 17 tempitem=getItemID(itemsbuf,itype_hookshot,1);
3313
3314
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3315
3316
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3317
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3318 {
3319 12 tempitemx=x;
3320 12 tempitemy=y;
3321 12 }
3322
3323 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3324 }
3325
3326 17 break;
3327
3328 case mfWAND:
3329
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(!hints)
3330 {
3331 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWAND],scr->secretcset[sWAND]);
3332 }
3333 else
3334 {
3335 35 tempitem=getItemID(itemsbuf,itype_wand,1);
3336
3337
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(tempitem<0) break;
3338
3339
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
35 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3340
3/6
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
35 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3341 {
3342 28 tempitemx=x;
3343 28 tempitemy=y;
3344 28 }
3345
3346 35 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3347 }
3348
3349 35 break;
3350
3351 case mfHAMMER:
3352
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3353 {
3354 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sHAMMER],scr->secretcset[sHAMMER]);
3355 }
3356 else
3357 {
3358 17 tempitem=getItemID(itemsbuf,itype_hammer,1);
3359
3360
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3361
3362
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3363
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3364 {
3365 13 tempitemx=x;
3366 13 tempitemy=y;
3367 13 }
3368
3369 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3370 }
3371
3372 17 break;
3373
3374 case mfARMOS_ITEM:
3375 case mfDIVE_ITEM:
3376 {
3377
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2602 times.
2602 int flag = (cur_screen < 128 && get_qr(qr_ITEMPICKUPSETSBELOW)) ? mITEM : mSPECIALITEM;
3378
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2602 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2602 times.
2602 if((!getmapflag(scr, flag) || (scr->flags9&fBELOWRETURN)) && !(itemsbuf[Hero.getLastLensID()].flags & item_flag3))
3379 {
3380 7806 putitem2(dest,x,y,scr->catchall, lens_hint_item[scr->catchall][0], lens_hint_item[scr->catchall][1], 0);
3381 2602 }
3382 2602 break;
3383 }
3384
3385 case 16:
3386 case 17:
3387 case 18:
3388 case 19:
3389 case 20:
3390 case 21:
3391 case 22:
3392 case 23:
3393 case 24:
3394 case 25:
3395 case 26:
3396 case 27:
3397 case 28:
3398 case 29:
3399 case 30:
3400 case 31:
3401
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 107890 times.
108898 if(!hints)
3402
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 107890 times.
215780 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3403 323670 putcombo(dest,x,y,scr->secretcombo[checkflag-16+4],scr->secretcset[checkflag-16+4]);
3404
3405 108898 break;
3406 case mfSECRETSNEXT:
3407 if(!hints)
3408 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3409 putcombo(dest,x,y,rpos_handle.data()+1,rpos_handle.cset());
3410
3411 break;
3412
3413 case mfSTRIKE:
3414
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3415 {
3416 906 goto special;
3417 }
3418 else
3419 {
3420 break;
3421 }
3422
3423 28750 default: goto special;
3424
3425 special:
3426
8/8
✓ Branch 0 taken 14732 times.
✓ Branch 1 taken 14924 times.
✓ Branch 2 taken 528 times.
✓ Branch 3 taken 14204 times.
✓ Branch 4 taken 496 times.
✓ Branch 5 taken 32 times.
✓ Branch 6 taken 6108 times.
✓ Branch 7 taken 8128 times.
29656 if(layer && ((checkflag!=mfRAFT && checkflag!=mfRAFT_BRANCH&& checkflag!=mfRAFT_BOUNCE) ||(itemsbuf[Hero.getLastLensID()].flags & item_flag4)))
3427 {
3428
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 6604 times.
✓ Branch 2 taken 4954 times.
✓ Branch 3 taken 1650 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1650 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6604 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate)) || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3429 {
3430 24770 rectfill(dest,x,y,x+15,y+15,WHITE);
3431 4954 }
3432 6604 }
3433
3434 29656 break;
3435 }
3436 7060416 }
3437 3530208 });
3438
3439 40116 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
3440 90824 auto [offx, offy] = translate_screen_coordinates_to_world(scr->screen);
3441
3442 40116 offx -= viewport.x;
3443 40116 offy -= viewport.y;
3444 40116 offy += playing_field_offset;
3445
3446
2/2
✓ Branch 0 taken 10029 times.
✓ Branch 1 taken 10029 times.
20058 if (layer)
3447 {
3448
2/2
✓ Branch 0 taken 9670 times.
✓ Branch 1 taken 359 times.
10029 if (scr->door[0]==dWALK)
3449 1795 rectfill(dest, 120+offx, 16+offy, 135+offx, 31+offy, WHITE);
3450
3451
2/2
✓ Branch 0 taken 9606 times.
✓ Branch 1 taken 423 times.
10029 if (scr->door[1]==dWALK)
3452 2115 rectfill(dest, 120+offx, 144+offy, 135+offx, 159+offy, WHITE);
3453
3454
2/2
✓ Branch 0 taken 9447 times.
✓ Branch 1 taken 582 times.
10029 if (scr->door[2]==dWALK)
3455 2910 rectfill(dest, 16+offx, 80+offy, 31+offx, 95+offy, WHITE);
3456
3457
2/2
✓ Branch 0 taken 9405 times.
✓ Branch 1 taken 624 times.
10029 if (scr->door[3]==dWALK)
3458 3120 rectfill(dest, 224+offx, 80+offy, 239+offx, 95+offy, WHITE);
3459
3460
2/2
✓ Branch 0 taken 9986 times.
✓ Branch 1 taken 43 times.
10029 if (scr->door[0]==dBOMB)
3461 {
3462 129 showbombeddoor(scr, dest, 0, offx, offy);
3463 43 }
3464
3465
2/2
✓ Branch 0 taken 9990 times.
✓ Branch 1 taken 39 times.
10029 if (scr->door[1]==dBOMB)
3466 {
3467 117 showbombeddoor(scr, dest, 1, offx, offy);
3468 39 }
3469
3470
2/2
✓ Branch 0 taken 10023 times.
✓ Branch 1 taken 6 times.
10029 if (scr->door[2]==dBOMB)
3471 {
3472 18 showbombeddoor(scr, dest, 2, offx, offy);
3473 6 }
3474
3475
2/2
✓ Branch 0 taken 9992 times.
✓ Branch 1 taken 37 times.
10029 if (scr->door[3]==dBOMB)
3476 {
3477 111 showbombeddoor(scr, dest, 3, offx, offy);
3478 37 }
3479 10029 }
3480
3481
3/4
✓ Branch 0 taken 18024 times.
✓ Branch 1 taken 2034 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18024 times.
20058 if (scr->stairx || scr->stairy)
3482 {
3483
2/2
✓ Branch 0 taken 911 times.
✓ Branch 1 taken 1123 times.
2034 if (!hints)
3484 {
3485
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1123 times.
1123 if (!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3486 3369 putcombo(dest,scr->stairx+offx,scr->stairy+offy,scr->secretcombo[sSTAIRS],scr->secretcset[sSTAIRS]);
3487 1123 }
3488 else
3489 {
3490
2/2
✓ Branch 0 taken 863 times.
✓ Branch 1 taken 48 times.
911 if(scr->flags&fWHISTLE)
3491 {
3492 48 tempitem=getItemID(itemsbuf,itype_whistle,1);
3493 48 int32_t tempitemx=-16+offx;
3494 48 int32_t tempitemy=-16+offy-playing_field_offset;
3495
3496
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&(blink_rate/4)))
3497
3/6
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&(blink_rate/4))))
3498 {
3499 48 tempitemx=scr->stairx+offx;
3500 48 tempitemy=scr->stairy+offy;
3501 24 }
3502
3503 48 putitem2(dest, tempitemx, tempitemy, tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3504 48 }
3505 }
3506 2034 }
3507 20058 });
3508 }
3509 20058 }
3510
3511 9690 void draw_lens_over(BITMAP *dest)
3512 {
3513 9690 int w = 288;
3514 9690 int h = 240;
3515
3516
4/6
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9672 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
9690 static BITMAP *lens_scr = create_bitmap_ex(8,2*w,2*h);
3517 static int32_t last_width = -1;
3518 9690 int32_t width = itemsbuf[current_item_id(itype_lens,true)].misc1;
3519
3520 // Only redraw the circle if the size has changed
3521
2/2
✓ Branch 0 taken 9670 times.
✓ Branch 1 taken 20 times.
9690 if (width != last_width)
3522 {
3523 20 clear_to_color(lens_scr, BLACK);
3524 20 circlefill(lens_scr, w, h, width, 0);
3525 20 circle(lens_scr, w, h, width+2, 0);
3526 20 circle(lens_scr, w, h, width+5, 0);
3527 20 last_width=width;
3528 20 }
3529
3530 9690 masked_blit(lens_scr, dest, w-(HeroX()+8)+viewport.x, h-(HeroY()+8)+viewport.y, 0, playing_field_offset, 256, viewport.h);
3531 9690 do_primitives(dest, SPLAYER_LENS_OVER);
3532 9690 }
3533
3534 38453398 static void update_bmp_size(BITMAP** bmp_ptr, int w, int h)
3535 {
3536 38453398 BITMAP* bmp = *bmp_ptr;
3537
3/4
✓ Branch 0 taken 38453398 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38453392 times.
✓ Branch 3 taken 6 times.
38453398 if (bmp->w == w && bmp->h == h)
3538 38453392 return;
3539
3540 6 int depth = bitmap_color_depth(bmp);
3541 6 destroy_bitmap(bmp);
3542 6 *bmp_ptr = create_bitmap_ex(depth, w, h);
3543 38453398 }
3544
3545 32028 void draw_wavy(BITMAP *source, BITMAP *target, int32_t amplitude, bool interpol)
3546 {
3547
4/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 32022 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
32028 static BITMAP *wavebuf = create_bitmap_ex(8,288,240-original_playing_field_offset);
3548 32028 update_bmp_size(&wavebuf, 288, 240 - original_playing_field_offset);
3549
3550 32028 clear_to_color(wavebuf, BLACK);
3551 32028 blit(source,wavebuf,0,original_playing_field_offset,16,0,256,framebuf->h-original_playing_field_offset);
3552
3553 int32_t ofs;
3554
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32028 times.
32028 amplitude = zc_min(2048,amplitude); // some arbitrary limit to prevent crashing
3555
4/6
✓ Branch 0 taken 32028 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 32028 times.
✓ Branch 4 taken 606 times.
✓ Branch 5 taken 31422 times.
32028 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY)) amplitude = zc_min(16,amplitude);
3556 32028 int32_t amp2 = viewport.visible_height(show_bottom_8px);
3557
2/4
✓ Branch 0 taken 32028 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 32028 times.
32028 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY_2)) amp2*=2;
3558 32028 int32_t i=frame%amp2;
3559
3560
2/2
✓ Branch 0 taken 5382552 times.
✓ Branch 1 taken 32028 times.
5414580 for(int32_t j=0; j<viewport.visible_height(show_bottom_8px); j++)
3561 {
3562
3/4
✓ Branch 0 taken 2691276 times.
✓ Branch 1 taken 2691276 times.
✓ Branch 2 taken 2691276 times.
✗ Branch 3 not taken.
5382552 if(j&1 && interpol)
3563 {
3564 // Add 288*2048 to ensure it's never negative. It'll get modded out.
3565 ofs=288*2048+int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3566 }
3567 else
3568 {
3569 5382552 ofs=288*2048-int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3570 }
3571
3572
1/2
✓ Branch 0 taken 5382552 times.
✗ Branch 1 not taken.
5382552 if(ofs)
3573 {
3574
2/2
✓ Branch 0 taken 1377933312 times.
✓ Branch 1 taken 5382552 times.
1383315864 for(int32_t k=0; k<256; k++)
3575 {
3576 1377933312 target->line[j+original_playing_field_offset][k]=wavebuf->line[j][(k+ofs+16)%288];
3577 1377933312 }
3578 5382552 }
3579 5382552 }
3580 32028 }
3581
3582 28272 void draw_fuzzy(int32_t fuzz)
3583 // draws from right half of scrollbuf to framebuf
3584 {
3585 int32_t firstx, firsty, xstep, ystep, i, y, dx, dy;
3586 byte *start, *si, *di;
3587
3588
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28272 times.
28272 if(fuzz<1)
3589 fuzz = 1;
3590
3591 28272 xstep = 128%fuzz;
3592
3593
2/2
✓ Branch 0 taken 5890 times.
✓ Branch 1 taken 22382 times.
28272 if(xstep > 0)
3594 22382 xstep = fuzz-xstep;
3595
3596 28272 ystep = 112%fuzz;
3597
3598
2/2
✓ Branch 0 taken 8246 times.
✓ Branch 1 taken 20026 times.
28272 if(ystep > 0)
3599 20026 ystep = fuzz-ystep;
3600
3601 28272 firsty = 1;
3602
3603
2/2
✓ Branch 0 taken 28272 times.
✓ Branch 1 taken 1020148 times.
1048420 for(y=0; y<framebuf->h;)
3604 {
3605 1020148 start = &(scrollbuf_old->line[y][256]);
3606
3607
4/4
✓ Branch 0 taken 1006012 times.
✓ Branch 1 taken 6347064 times.
✓ Branch 2 taken 6332928 times.
✓ Branch 3 taken 1020148 times.
7353076 for(dy=0; dy<ystep && dy+y<framebuf->h; dy++)
3608 {
3609 6332928 si = start;
3610 6332928 di = &(framebuf->line[y+dy][0]);
3611 6332928 i = xstep;
3612 6332928 firstx = 1;
3613
3614
2/2
✓ Branch 0 taken 1621229568 times.
✓ Branch 1 taken 6332928 times.
1627562496 for(dx=0; dx<framebuf->w; dx++)
3615 {
3616 1621229568 *(di++) = *si;
3617
3618
2/2
✓ Branch 0 taken 1366065344 times.
✓ Branch 1 taken 255164224 times.
1621229568 if(++i >= fuzz)
3619 {
3620
2/2
✓ Branch 0 taken 248831296 times.
✓ Branch 1 taken 6332928 times.
255164224 if(!firstx)
3621 248831296 si += fuzz;
3622 else
3623 {
3624 6332928 si += fuzz-xstep;
3625 6332928 firstx = 0;
3626 }
3627
3628 255164224 i = 0;
3629 255164224 }
3630 1621229568 }
3631 6332928 }
3632
3633
2/2
✓ Branch 0 taken 991876 times.
✓ Branch 1 taken 28272 times.
1020148 if(!firsty)
3634 991876 y += fuzz;
3635 else
3636 {
3637 28272 y += ystep;
3638 28272 ystep = fuzz;
3639 28272 firsty = 0;
3640 }
3641 }
3642 28272 }
3643
3644 19210685 void updatescr(bool allowwavy)
3645 {
3646
4/6
✓ Branch 0 taken 325 times.
✓ Branch 1 taken 19210360 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 325 times.
✓ Branch 4 taken 325 times.
✗ Branch 5 not taken.
19210685 static BITMAP *wavybuf = create_bitmap_ex(8, framebuf->w, framebuf->h);
3647
4/6
✓ Branch 0 taken 325 times.
✓ Branch 1 taken 19210360 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 325 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 325 times.
19210685 static BITMAP *panorama = create_bitmap_ex(8, framebuf->w, framebuf->h);
3648 19210685 update_bmp_size(&wavybuf, framebuf->w, framebuf->h);
3649 19210685 update_bmp_size(&panorama, framebuf->w, framebuf->h);
3650
3651
2/2
✓ Branch 0 taken 19182544 times.
✓ Branch 1 taken 28141 times.
19210685 if(walk_through_walls)
3652 {
3653 28141 textout_ex(framebuf,font,"no walls",8,216,1,-1);
3654 28141 }
3655
3656
1/2
✓ Branch 0 taken 19210685 times.
✗ Branch 1 not taken.
19210685 if(Showpal)
3657 dump_pal(framebuf);
3658
3659
2/2
✓ Branch 0 taken 18686634 times.
✓ Branch 1 taken 524051 times.
19210685 if(!Playing)
3660 524051 black_opening_count=0;
3661
3662
2/2
✓ Branch 0 taken 19032557 times.
✓ Branch 1 taken 178128 times.
19210685 if(black_opening_count<0) //shape is opening up
3663 {
3664 178128 black_opening(framebuf,black_opening_x,black_opening_y,(66+black_opening_count),66);
3665
3666
2/4
✓ Branch 0 taken 178128 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 178128 times.
178128 if(Advance||(!Paused))
3667 {
3668 178128 ++black_opening_count;
3669 178128 }
3670 178128 }
3671
2/2
✓ Branch 0 taken 18983717 times.
✓ Branch 1 taken 48840 times.
19032557 else if(black_opening_count>0) //shape is closing
3672 {
3673 48840 black_opening(framebuf,black_opening_x,black_opening_y,black_opening_count,66);
3674
3675
2/4
✓ Branch 0 taken 48840 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 48840 times.
48840 if(Advance||(!Paused))
3676 {
3677 48840 --black_opening_count;
3678 48840 }
3679 48840 }
3680
3681
3/4
✓ Branch 0 taken 18987154 times.
✓ Branch 1 taken 223531 times.
✓ Branch 2 taken 18987154 times.
✗ Branch 3 not taken.
19210685 if(black_opening_count==0&&black_opening_shape==bosFADEBLACK)
3682 {
3683 black_opening_shape = bosCIRCLE;
3684 memcpy(RAMpal, tempblackpal, PAL_SIZE*sizeof(RGB));
3685 refreshTints();
3686 refreshpal=true;
3687 }
3688
3689
2/2
✓ Branch 0 taken 18575275 times.
✓ Branch 1 taken 635410 times.
19210685 if(refreshpal)
3690 {
3691 635410 refreshpal=false;
3692 635410 RAMpal[253] = _RGB(0,0,0);
3693 635410 RAMpal[254] = _RGB(255,255,255);
3694 635410 hw_palette = &RAMpal;
3695 635410 update_hw_pal = true;
3696 635410 refresh_rgb_tables();
3697 635410 }
3698
3699 19210685 bool clearwavy = (wavy <= 0);
3700
3701
2/2
✓ Branch 0 taken 8572 times.
✓ Branch 1 taken 19202113 times.
19210685 if(wavy <= 0)
3702 {
3703 // So far one thing can alter wavy apart from scripts: Wavy DMaps.
3704 19202113 wavy = (DMaps[cur_dmap].flags&dmfWAVY ? 4 : 0);
3705 19202113 }
3706
3707 19210685 blit(framebuf, wavybuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
3708
3709
6/6
✓ Branch 0 taken 32278 times.
✓ Branch 1 taken 19178407 times.
✓ Branch 2 taken 32156 times.
✓ Branch 3 taken 122 times.
✓ Branch 4 taken 128 times.
✓ Branch 5 taken 32028 times.
19210685 if(wavy && Playing && allowwavy)
3710 {
3711 32028 draw_wavy(framebuf, wavybuf, wavy,false);
3712 32028 }
3713
3714
2/2
✓ Branch 0 taken 19202113 times.
✓ Branch 1 taken 8572 times.
19210685 if(clearwavy)
3715 19202113 wavy = 0; // Wavy was set by a DMap flag. Clear it.
3716
2/4
✓ Branch 0 taken 8572 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8572 times.
8572 else if(Playing && !Paused)
3717 8572 wavy--; // Wavy was set by a script. Decrement it.
3718
3719
3/4
✓ Branch 0 taken 18686634 times.
✓ Branch 1 taken 524051 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18686634 times.
19210685 if(Playing && !Paused)
3720 18686634 ++light_wave_clk;
3721
3722
6/6
✓ Branch 0 taken 18686634 times.
✓ Branch 1 taken 524051 times.
✓ Branch 2 taken 277060 times.
✓ Branch 3 taken 18409574 times.
✓ Branch 4 taken 68 times.
✓ Branch 5 taken 276992 times.
19210685 if(Playing && msg_active && !screenscrolling)
3723 {
3724
2/2
✓ Branch 0 taken 133 times.
✓ Branch 1 taken 276859 times.
276992 if(!(msg_bg_display_buf->clip))
3725 276859 blit_msgstr_bg(framebuf,0,0,0,playing_field_offset,256,176);
3726
2/2
✓ Branch 0 taken 133 times.
✓ Branch 1 taken 276859 times.
276992 if(!(msg_portrait_display_buf->clip))
3727 276859 blit_msgstr_prt(framebuf,0,0,0,playing_field_offset,256,176);
3728
2/2
✓ Branch 0 taken 133 times.
✓ Branch 1 taken 276859 times.
276992 if(!(msg_txt_display_buf->clip))
3729 276859 blit_msgstr_fg(framebuf,0,0,0,playing_field_offset,256,176);
3730 276992 }
3731
3732
3/4
✓ Branch 0 taken 19210685 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19004618 times.
✓ Branch 3 taken 206067 times.
19210685 bool nosubscr = GameLoaded && no_subscreen() && !(hero_scr->flags3&fNOSUBSCROFFSET);
3733
3734
2/2
✓ Branch 0 taken 19009891 times.
✓ Branch 1 taken 200794 times.
19210685 if(nosubscr)
3735 {
3736 200794 clear_to_color(panorama, 0);
3737 200794 blit(wavybuf,panorama,0,playing_field_offset,0,playing_field_offset/2,256,framebuf->h-playing_field_offset);
3738 200794 }
3739
3740 //TODO: Optimize blit 'overcalls' -Gleeok
3741
2/2
✓ Branch 0 taken 200794 times.
✓ Branch 1 taken 19009891 times.
19210685 BITMAP *source = nosubscr ? panorama : wavybuf;
3742 19210685 blit(source, framebuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
3743
3744 19210685 update_hw_screen();
3745 19210685 }
3746
3747 //----------------------------------------------------------------
3748
3749 static PALETTE syspal;
3750 int32_t onGUISnapshot()
3751 {
3752 char buf[200];
3753 int32_t num=0;
3754 do
3755 {
3756 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3757 }
3758 while(num<99999 && exists(buf));
3759
3760 if (!al_save_bitmap(buf, al_get_backbuffer(all_get_display())))
3761 InfoDialog("Error", "Failed to save snapshot").show();
3762
3763 return D_O_K;
3764 }
3765
3766 int32_t onNonGUISnapshot()
3767 {
3768 PALETTE temppal;
3769 get_palette(temppal);
3770 bool realpal=(zc_getkey(KEY_ZC_LCONTROL, true) || zc_getkey(KEY_ZC_RCONTROL, true));
3771
3772 char buf[200];
3773 int32_t num=0;
3774
3775 do
3776 {
3777 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3778 }
3779 while(num<99999 && exists(buf));
3780
3781 if (hero_scr && no_subscreen() && !(hero_scr->flags3&fNOSUBSCROFFSET) && !key[KEY_ALT])
3782 {
3783 BITMAP *b = create_bitmap_ex(8, 256, viewport.visible_height(show_bottom_8px));
3784 clear_to_color(b,0);
3785 blit(framebuf,b,0,playing_field_offset/2,0,0,b->w,b->h);
3786 alleg4_save_bitmap(b, SnapshotScale, buf, realpal ? temppal : RAMpal);
3787 destroy_bitmap(b);
3788 }
3789 else
3790 {
3791 alleg4_save_bitmap(framebuf, SnapshotScale, buf, realpal?temppal:RAMpal);
3792 }
3793
3794 return D_O_K;
3795 }
3796
3797 int32_t onSnapshot()
3798 {
3799 if(zc_getkey(KEY_LSHIFT, true)||zc_getkey(KEY_RSHIFT, true))
3800 {
3801 onGUISnapshot();
3802 }
3803 else
3804 {
3805 onNonGUISnapshot();
3806 }
3807
3808 return D_O_K;
3809 }
3810
3811 int32_t onSaveMapPic()
3812 {
3813 char buf[200];
3814 int32_t num=0;
3815 BITMAP* _screen_draw_buffer = NULL;
3816 _screen_draw_buffer = create_bitmap_ex(8,256,176);
3817
3818 do
3819 {
3820 sprintf(buf, "%szc_screen%05d.png", get_snap_str(), ++num);
3821 }
3822 while(num<99999 && exists(buf));
3823
3824 BITMAP* mappic = create_bitmap_ex(8,(256*16),(176*8));
3825 clear_to_color(mappic, BLACK);
3826
3827 if(!mappic)
3828 {
3829 enter_sys_pal();
3830 jwin_alert("View Map","Not enough memory.",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
3831 exit_sys_pal();
3832 return D_O_K;;
3833 }
3834
3835 clear_to_color(_screen_draw_buffer, BLACK);
3836
3837 auto prev_viewport = viewport;
3838 viewport.x = 0;
3839 viewport.y = 0;
3840
3841 // draw the map
3842
3843 bool classic_draw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3844 for(int32_t y=0; y<8; y++)
3845 {
3846 for(int32_t x=0; x<16; x++)
3847 {
3848 if (!displayOnMap(x, y))
3849 continue;
3850
3851 int screen = map_scr_xy_to_index(x, y);
3852 auto scrs = loadscr2(screen);
3853 mapscr* scr = &scrs[0];
3854 if (!scr->is_valid())
3855 continue;
3856
3857 screen_handles_t screen_handles;
3858 for (int i = 0; i <= 6; i++)
3859 screen_handles[i] = {scr, scrs[i].is_valid() ? &scrs[i] : nullptr, screen, i};
3860
3861 int xx = 0;
3862 int yy = -playing_field_offset;
3863
3864 if (!classic_draw)
3865 for (int layer = -7; layer <= -4; ++layer)
3866 do_ffc_layer(_screen_draw_buffer, layer, screen_handles[0], xx, yy);
3867
3868 if(classic_draw)
3869 {
3870 if(XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3871 do_layer(_screen_draw_buffer, 0, screen_handles[2], xx, yy);
3872 do_ffc_layer(_screen_draw_buffer, -2, screen_handles[0], xx, yy);
3873 }
3874
3875 if(XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
3876 do_layer(_screen_draw_buffer, 0, screen_handles[3], xx, yy);
3877 do_ffc_layer(_screen_draw_buffer, -3, screen_handles[0], xx, yy);
3878
3879 if(!classic_draw)
3880 {
3881 if(XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3882 do_layer(_screen_draw_buffer, 0, screen_handles[2], xx, yy);
3883 do_ffc_layer(_screen_draw_buffer, -2, screen_handles[0], xx, yy);
3884 do_ffc_layer(_screen_draw_buffer, -1, screen_handles[0], xx, yy);
3885 }
3886
3887 if(lenscheck(scr,0))
3888 putscr(scr, _screen_draw_buffer, 0, 0);
3889 do_ffc_layer(_screen_draw_buffer, 0, screen_handles[0], xx, yy);
3890 do_layer(_screen_draw_buffer, 0, screen_handles[1], xx, yy);
3891 do_ffc_layer(_screen_draw_buffer, 1, screen_handles[0], xx, yy);
3892
3893 if(!XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3894 {
3895 do_layer(_screen_draw_buffer, 0, screen_handles[2], xx, yy);
3896 do_ffc_layer(_screen_draw_buffer, 2, screen_handles[0], xx, yy);
3897 }
3898
3899 putscrdoors(scr, _screen_draw_buffer, xx, yy);
3900 if(get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
3901 {
3902 do_layer(_screen_draw_buffer, -2, screen_handles[0], xx, yy);
3903 if(get_qr(qr_PUSHBLOCK_LAYER_1_2))
3904 {
3905 do_layer(_screen_draw_buffer, -2, screen_handles[1], xx, yy);
3906 do_layer(_screen_draw_buffer, -2, screen_handles[2], xx, yy);
3907 }
3908 }
3909
3910 if(!XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
3911 {
3912 do_layer(_screen_draw_buffer, 0, screen_handles[3], xx, yy);
3913 do_ffc_layer(_screen_draw_buffer, 3, screen_handles[0], xx, yy);
3914 }
3915
3916 do_layer(_screen_draw_buffer, 0, screen_handles[4], xx, yy);
3917 do_ffc_layer(_screen_draw_buffer, 4, screen_handles[0], xx, yy);
3918 do_layer(_screen_draw_buffer, -1, screen_handles[0], xx, yy);
3919 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3920 {
3921 do_layer(_screen_draw_buffer, -1, screen_handles[1], xx, yy);
3922 do_layer(_screen_draw_buffer, -1, screen_handles[2], xx, yy);
3923 }
3924 do_layer(_screen_draw_buffer, 0, screen_handles[5], xx, yy);
3925 do_ffc_layer(_screen_draw_buffer, 5, screen_handles[0], xx, yy);
3926 if(replay_version_check(40))
3927 do_ffc_layer(_screen_draw_buffer, -1000, screen_handles[0], xx, yy);
3928 do_layer(_screen_draw_buffer, 0, screen_handles[6], xx, yy);
3929 do_ffc_layer(_screen_draw_buffer, 6, screen_handles[0], xx, yy);
3930 do_ffc_layer(_screen_draw_buffer, 7, screen_handles[0], xx, yy);
3931
3932 blit(_screen_draw_buffer, mappic, 0, 0, x*256, y*176, 256, 176);
3933 }
3934 }
3935
3936 viewport = prev_viewport;
3937 save_bitmap(buf,mappic,RAMpal);
3938 destroy_bitmap(mappic);
3939 destroy_bitmap(_screen_draw_buffer);
3940 return D_O_K;
3941 }
3942
3943 59 void f_Quit(int32_t type)
3944 {
3945
2/4
✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 59 times.
✗ Branch 3 not taken.
59 if(type==qQUIT && !Playing)
3946 return;
3947
3948 59 bool from_menu = is_sys_pal;
3949
3950
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
59 if(!from_menu)
3951 {
3952 59 music_pause();
3953 59 pause_all_sfx();
3954 59 sys_mouse();
3955 59 }
3956 59 enter_sys_pal();
3957 59 clear_keybuf();
3958
3959
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 13 times.
59 if (replay_version_check(0, 10))
3960 13 replay_poll();
3961
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
59 if (replay_is_replaying())
3962 59 replay_peek_quit();
3963
3964
1/2
✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
59 if (!replay_is_replaying())
3965 switch(type)
3966 {
3967 case qQUIT:
3968 onQuit();
3969 break;
3970
3971 case qRESET:
3972 onReset();
3973 break;
3974
3975 case qEXIT:
3976 onExit();
3977 break;
3978 }
3979
3980
1/2
✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
59 if(Quit)
3981 {
3982 59 kill_sfx();
3983 59 music_stop();
3984 59 exit_sys_pal();
3985 59 update_hw_screen();
3986 59 }
3987 else
3988 {
3989 exit_sys_pal();
3990 if(!from_menu)
3991 {
3992 music_resume();
3993 resume_all_sfx();
3994 }
3995 }
3996
3997
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
59 if(!from_menu)
3998 59 game_mouse();
3999 59 eat_buttons();
4000
4001 59 zc_readrawkey(KEY_ESC);
4002
4003 59 zc_readrawkey(KEY_ENTER);
4004 59 }
4005
4006 //----------------------------------------------------------------
4007
4008 int32_t onNoWalls()
4009 {
4010 cheats_enqueue(Cheat::Walls);
4011 return D_O_K;
4012 }
4013
4014 int32_t onIgnoreSideview()
4015 {
4016 cheats_enqueue(Cheat::IgnoreSideView);
4017 return D_O_K;
4018 }
4019
4020 19209276 int32_t input_idle(bool checkmouse)
4021 {
4022 static int32_t mx, my, mz, mb;
4023
4024
4/6
✓ Branch 0 taken 19209276 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5121027 times.
✓ Branch 3 taken 14088249 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5121027 times.
24330303 if(keypressed() || zc_key_pressed() ||
4025
4/8
✓ Branch 0 taken 5121027 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5121027 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5121027 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5121027 times.
✗ Branch 7 not taken.
5121027 (checkmouse && (mx != mouse_x || my != mouse_y || mz != mouse_z || mb != mouse_b)))
4026 {
4027 14088249 idle_count = 0;
4028
4029
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14088249 times.
14088249 if(active_count < MAX_ACTIVE)
4030 {
4031 14088249 ++active_count;
4032 14088249 }
4033 14088249 }
4034
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5121027 times.
5121027 else if(idle_count < MAX_IDLE)
4035 {
4036 5121027 ++idle_count;
4037 5121027 active_count = 0;
4038 5121027 }
4039
4040 19209276 mx = mouse_x;
4041 19209276 my = mouse_y;
4042 19209276 mz = mouse_z;
4043 19209276 mb = mouse_b;
4044
4045 19209276 return idle_count;
4046 }
4047
4048 int32_t onGoFast()
4049 {
4050 cheats_enqueue(Cheat::Fast);
4051 return D_O_K;
4052 }
4053
4054 int32_t onKillCheat()
4055 {
4056 cheats_enqueue(Cheat::Kill);
4057 return D_O_K;
4058 }
4059
4060 int32_t onSecretsCheat()
4061 {
4062 cheats_enqueue(Cheat::TrigSecrets);
4063 return D_O_K;
4064 }
4065 int32_t onSecretsCheatPerm()
4066 {
4067 cheats_enqueue(Cheat::TrigSecretsPerm);
4068 return D_O_K;
4069 }
4070
4071 int32_t onShowLayer0()
4072 {
4073 show_layers[0] = !show_layers[0];
4074 return D_O_K;
4075 }
4076 int32_t onShowLayer1()
4077 {
4078 show_layers[1] = !show_layers[1];
4079 return D_O_K;
4080 }
4081 int32_t onShowLayer2()
4082 {
4083 show_layers[2] = !show_layers[2];
4084 return D_O_K;
4085 }
4086 int32_t onShowLayer3()
4087 {
4088 show_layers[3] = !show_layers[3];
4089 return D_O_K;
4090 }
4091 int32_t onShowLayer4()
4092 {
4093 show_layers[4] = !show_layers[4];
4094 return D_O_K;
4095 }
4096 int32_t onShowLayer5()
4097 {
4098 show_layers[5] = !show_layers[5];
4099 return D_O_K;
4100 }
4101 int32_t onShowLayer6()
4102 {
4103 show_layers[6] = !show_layers[6];
4104 return D_O_K;
4105 }
4106 int32_t onShowLayerO()
4107 {
4108 show_layer_over=!show_layer_over;
4109 return D_O_K;
4110 }
4111 int32_t onShowLayerP()
4112 {
4113 show_layer_push=!show_layer_push;
4114 return D_O_K;
4115 }
4116 int32_t onShowLayerS()
4117 {
4118 show_sprites=!show_sprites;
4119 return D_O_K;
4120 }
4121 int32_t onShowLayerF()
4122 {
4123 show_ffcs=!show_ffcs;
4124 return D_O_K;
4125 }
4126 int32_t onShowLayerW()
4127 {
4128 show_walkflags=!show_walkflags;
4129 if(show_walkflags)
4130 show_effectflags = false;
4131 return D_O_K;
4132 }
4133 int32_t onShowLayerE()
4134 {
4135 show_effectflags=!show_effectflags;
4136 if(show_effectflags)
4137 show_walkflags = false;
4138 return D_O_K;
4139 }
4140 int32_t onShowFFScripts()
4141 {
4142 show_ff_scripts=!show_ff_scripts;
4143 return D_O_K;
4144 }
4145 2 int32_t onShowHitboxes()
4146 {
4147 2 show_hitboxes=!show_hitboxes;
4148 2 return D_O_K;
4149 }
4150 int32_t onShowInfoOpacity()
4151 {
4152 info_opacity = vbound(getnumber("Debug Info Opacity",info_opacity),0,255);
4153 zc_set_config("zc","debug_info_opacity",info_opacity);
4154 return D_O_K;
4155 }
4156
4157 int32_t onLightSwitch()
4158 {
4159 cheats_enqueue(Cheat::Light);
4160 return D_O_K;
4161 }
4162
4163 int32_t onGoTo();
4164 int32_t onGoToComplete();
4165
4166 19209276 bool handle_close_btn_quit()
4167 {
4168
1/2
✓ Branch 0 taken 19209276 times.
✗ Branch 1 not taken.
19209276 if(close_button_quit)
4169 {
4170 close_button_quit=false;
4171 f_Quit(qEXIT);
4172 }
4173 19209276 return (exiting_program = Quit==qEXIT);
4174 }
4175
4176 19209276 void syskeys()
4177 {
4178 19209276 update_system_keys();
4179
4180 int32_t oldtitle_version;
4181
4182 19209276 poll_joystick();
4183
4184 19209276 handle_close_btn_quit();
4185
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19209276 times.
19209276 if(Quit == qEXIT) return;
4186
4187
2/10
✓ Branch 0 taken 19209276 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19209276 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
19209276 if(rMbtn() || (gui_mouse_b() && !mouse_down && ClickToFreeze &&!disableClickToFreeze))
4188 {
4189 System();
4190 }
4191
4192 19209276 mouse_down=gui_mouse_b();
4193
4194
1/2
✓ Branch 0 taken 19209276 times.
✗ Branch 1 not taken.
19209276 if(zc_read_system_key(KEY_F1))
4195 {
4196 if(zc_get_system_key(KEY_ZC_LCONTROL) || zc_get_system_key(KEY_ZC_RCONTROL))
4197 {
4198 halt=!halt;
4199 //zinit.subscreen=(zinit.subscreen+1)%ssdtMAX;
4200 }
4201 else
4202 {
4203 Throttlefps=!Throttlefps;
4204 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4205 }
4206 }
4207
4208
1/2
✓ Branch 0 taken 19209276 times.
✗ Branch 1 not taken.
19209276 if(zc_read_system_key(KEY_F2))
4209 {
4210 ShowFPS=!ShowFPS;
4211 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
4212 }
4213
4214
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 19209276 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
19209276 if(zc_read_system_key(KEY_F3) && Playing) Paused=!Paused;
4215
4216
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 19209276 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
19209276 if(zc_read_system_key(KEY_F4) && Playing)
4217 {
4218 Paused=true;
4219 Advance=true;
4220 }
4221
4222
1/2
✓ Branch 0 taken 19209276 times.
✗ Branch 1 not taken.
19209276 if(zc_read_system_key(KEY_F6)) onTryQuit();
4223
4224 #ifndef ALLEGRO_MACOSX
4225
1/2
✓ Branch 0 taken 19209276 times.
✗ Branch 1 not taken.
19209276 if(zc_read_system_key(KEY_F9)) f_Quit(qRESET);
4226
4227
1/2
✓ Branch 0 taken 19209276 times.
✗ Branch 1 not taken.
19209276 if(zc_read_system_key(KEY_F10)) f_Quit(qEXIT);
4228 #else
4229 if(zc_read_system_key(KEY_F7)) f_Quit(qRESET);
4230
4231 if(zc_read_system_key(KEY_F8)) f_Quit(qEXIT);
4232 #endif
4233
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 19209276 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
19209276 if(zc_read_system_key(KEY_F5)&&(Playing && cur_screen<128 && DMaps[cur_dmap].flags&dmfVIEWMAP)) onSaveMapPic();
4234
4235
1/2
✓ Branch 0 taken 19209276 times.
✗ Branch 1 not taken.
19209276 if (zc_read_system_key(KEY_F12))
4236 {
4237 onSnapshot();
4238 }
4239
4240
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 19209276 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
19209276 if(debug_enabled && zc_read_system_key(KEY_TAB))
4241 set_debug(!get_debug());
4242
4243
1/2
✓ Branch 0 taken 19209276 times.
✗ Branch 1 not taken.
19209276 if(CheatModifierKeys())
4244 {
4245 for(Cheat c = (Cheat)1; c < Cheat::Last; c = (Cheat)(c+1))
4246 {
4247 if(!bindable_cheat(c))
4248 continue;
4249 if(get_debug() || cheat >= cheat_lvl(c))
4250 {
4251 if(checkcheat(c))
4252 cheats_hit_bind(c);
4253 }
4254 }
4255 }
4256
4257
1/2
✓ Branch 0 taken 19209276 times.
✗ Branch 1 not taken.
19209276 if(volkeys)
4258 {
4259 if(zc_read_system_key(KEY_PGUP)) master_volume(-1,midi_volume+8);
4260
4261 if(zc_read_system_key(KEY_PGDN)) master_volume(-1,midi_volume==255?248:midi_volume-8);
4262
4263 if(zc_read_system_key(KEY_HOME)) master_volume(digi_volume+8,-1);
4264
4265 if(zc_read_system_key(KEY_END)) master_volume(digi_volume==255?248:digi_volume-8,-1);
4266 }
4267
4268
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 19209276 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
19209276 if(!get_debug() || !SystemKeys || replay_is_replaying())
4269 19209276 goto bottom;
4270
4271 if(zc_readkey(KEY_P)) Paused=!Paused;
4272
4273 if(zc_readkey(KEY_A))
4274 {
4275 Paused=true;
4276 Advance=true;
4277 }
4278
4279 if(zc_readkey(KEY_G)) db=(db==999)?0:999;
4280 #ifndef ALLEGRO_MACOSX
4281 if(zc_readkey(KEY_F8)) Showpal=!Showpal;
4282
4283 if(zc_readkey(KEY_F7))
4284 {
4285 Matrix(ss_speed, ss_density, 0);
4286 game_pal();
4287 }
4288 #else
4289 // The reason these are different on Mac in the first place is that
4290 // the OS doesn't let us use F9 and F10...
4291 if(zc_readkey(KEY_F10)) Showpal=!Showpal;
4292
4293 if(zc_readkey(KEY_F9))
4294 {
4295 Matrix(ss_speed, ss_density, 0);
4296 game_pal();
4297 }
4298 #endif
4299 if(zc_readkey(KEY_PLUS_PAD) || zc_readkey(KEY_EQUALS))
4300 {
4301 //change containers
4302 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4303 {
4304 //magic containers
4305 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4306 {
4307 game->set_maxmagic(zc_min(game->get_maxmagic()+game->get_mp_per_block(),game->get_mp_per_block()*8));
4308 }
4309 else
4310 {
4311 game->set_maxlife(zc_min(game->get_maxlife()+game->get_hp_per_heart(),game->get_hp_per_heart()*24));
4312 }
4313 }
4314 else
4315 {
4316 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4317 {
4318 game->set_magic(zc_min(game->get_magic()+1,game->get_maxmagic()));
4319 }
4320 else
4321 {
4322 game->set_life(zc_min(game->get_life()+1,game->get_maxlife()));
4323 }
4324 }
4325 }
4326
4327 if(zc_readkey(KEY_MINUS_PAD) || zc_readkey(KEY_MINUS))
4328 {
4329 //change containers
4330 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4331 {
4332 //magic containers
4333 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4334 {
4335 game->set_maxmagic(zc_max(game->get_maxmagic()-game->get_mp_per_block(),0));
4336 game->set_magic(zc_min(game->get_maxmagic(), game->get_magic()));
4337 //heart containers
4338 }
4339 else
4340 {
4341 game->set_maxlife(zc_max(game->get_maxlife()-game->get_hp_per_heart(),game->get_hp_per_heart()));
4342 game->set_life(zc_min(game->get_maxlife(), game->get_life()));
4343 }
4344 }
4345 else
4346 {
4347 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4348 {
4349 game->set_magic(zc_max(game->get_magic()-1,0));
4350 }
4351 else
4352 {
4353 game->set_life(zc_max(game->get_life()-1,0));
4354 }
4355 }
4356 }
4357
4358 if(zc_readkey(KEY_COMMA)) jukebox(currmidi-1);
4359
4360 if(zc_readkey(KEY_STOP)) jukebox(currmidi+1);
4361
4362 verifyBothWeapons();
4363
4364 bottom:
4365
4366
1/2
✓ Branch 0 taken 19209276 times.
✗ Branch 1 not taken.
19209276 if(input_idle(true) > after_time())
4367 {
4368 Matrix(ss_speed, ss_density, 0);
4369 game_pal();
4370 }
4371 19209276 }
4372
4373 1551416 void checkQuitKeys()
4374 {
4375 #ifndef ALLEGRO_MACOSX
4376
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1551416 times.
1551416 if(key[KEY_F9]) f_Quit(qRESET);
4377
4378
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1551416 times.
1551416 if(key[KEY_F10]) f_Quit(qEXIT);
4379 #else
4380 if(key[KEY_F7]) f_Quit(qRESET);
4381
4382 if(key[KEY_F8]) f_Quit(qEXIT);
4383 #endif
4384 1551416 }
4385
4386 19209476 bool CheatModifierKeys()
4387 {
4388 // Cheats are replayed via the X cheat step, no need to check for keyboard input
4389 // to trigger cheats.
4390
2/2
✓ Branch 0 taken 19209176 times.
✓ Branch 1 taken 300 times.
19209476 if (replay_is_replaying())
4391 19209176 return false;
4392
4393
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 200 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
300 if ( ( cheat_modifier_keys[0] > 0 && key[cheat_modifier_keys[0]] ) ||
4394
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 100 times.
200 ( cheat_modifier_keys[1] > 0 && key[cheat_modifier_keys[1]] ) ||
4395
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
100 (cheat_modifier_keys[0] <= 0 && cheat_modifier_keys[1] <= 0))
4396 {
4397
0/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
200 if ( ( cheat_modifier_keys[2] <= 0 || key[cheat_modifier_keys[2]] ) ||
4398 ( cheat_modifier_keys[3] > 0 && key[cheat_modifier_keys[3]] ) ||
4399 (cheat_modifier_keys[2] <= 0 && cheat_modifier_keys[3] <= 0))
4400 {
4401 return true;
4402 }
4403 }
4404 100 return false;
4405 19209276 }
4406
4407 //99:05:54, for some reason?
4408 #define OLDMAXTIME 21405240
4409 //9000:00:00, the highest even-thousand hour fitting within 32b signed. This is 375 *DAYS*.
4410 #define MAXTIME 1944000000
4411
4412 // (qr, value)
4413 429 static std::queue<std::pair<int, bool>> change_qr_queue;
4414
4415 7 void enqueue_qr_change(int qr, bool value)
4416 {
4417 7 change_qr_queue.push({qr, value});
4418 7 }
4419
4420 // During regular play, QR changes issued through `syskey` / `System` and enqueued
4421 // and soon executed here.
4422 // During playing back a replay file, the replay system adds to the same queue and
4423 // is executed here too.
4424 // This is currently only used to allow users to configure qr_HIDE_BOTTOM_8_PIXELS, but
4425 // could be later extended to all QRs (perhaps as a cheat).
4426 19209713 void process_enqueued_qr_changes()
4427 {
4428
2/2
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 19209612 times.
19209713 if (replay_is_replaying())
4429 19209612 replay_do_qrs();
4430
4431
2/2
✓ Branch 0 taken 19209713 times.
✓ Branch 1 taken 7 times.
19209720 while (!change_qr_queue.empty())
4432 {
4433 28 auto [qr, value] = change_qr_queue.front();
4434 7 change_qr_queue.pop();
4435
4436 // Don't modify `quest_rules`, as that is used to store the canonical QR value which can be reset to
4437 // via system menus. Changing the unpacked array is enough to modify the engine's behavior.
4438 14 _qrs_unpacked[qr] = value;
4439 7 apply_qr_rule(qr);
4440
4441
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
7 if (replay_is_recording())
4442 2 replay_step_qr(qr, value);
4443 }
4444 19209713 }
4445
4446 19210685 void advanceframe(bool allowwavy, bool sfxcleanup, bool allowF6Script)
4447 {
4448
1/2
✓ Branch 0 taken 19210685 times.
✗ Branch 1 not taken.
19210685 if(zcmusic!=NULL)
4449 {
4450 zcmusic_poll();
4451 }
4452 19210685 zcmixer_update(zcmixer, emusic_volume, FFCore.usr_music_volume, get_qr(qr_OLD_SCRIPT_VOLUME));
4453
4454 19210685 updatescr(allowwavy);
4455
4456 19210685 Advance=false;
4457
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 19210685 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 19210685 times.
19210685 while(Paused && !Advance && !Quit)
4458 {
4459 // have to call this, otherwise we'll get an infinite loop
4460 syskeys();
4461 if(allowF6Script)
4462 {
4463 FFCore.runF6Engine();
4464 }
4465
4466 #ifdef _WIN32
4467
4468 if(use_dwm_flush)
4469 {
4470 do_DwmFlush();
4471 }
4472
4473 #endif
4474
4475 // to keep music playing
4476 if(zcmusic!=NULL)
4477 {
4478 zcmusic_poll();
4479 }
4480
4481 update_hw_screen();
4482 }
4483
4484
2/2
✓ Branch 0 taken 19209306 times.
✓ Branch 1 taken 1379 times.
19210685 if(Quit)
4485 1379 return;
4486
4487
3/4
✓ Branch 0 taken 18685582 times.
✓ Branch 1 taken 523724 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18685582 times.
19209306 if(Playing && game->get_time()<unsigned(get_qr(qr_GREATER_MAX_TIME) ? MAXTIME : OLDMAXTIME))
4488 18685582 game->change_time(1);
4489
4490 // Many mistakes have been make re: inputs, and we are stuck with many replays relying on those mistakes.
4491
4492 19209306 bool should_reset_down_state = !get_qr(qr_BROKEN_INPUT_DOWN_STATE);
4493
2/2
✓ Branch 0 taken 9430740 times.
✓ Branch 1 taken 9778566 times.
19209306 if (replay_version_check(0, 16))
4494 9778566 should_reset_down_state = replay_version_check(11, 16);
4495
2/2
✓ Branch 0 taken 15075659 times.
✓ Branch 1 taken 4133647 times.
19209306 if (should_reset_down_state)
4496 {
4497
2/2
✓ Branch 0 taken 74405646 times.
✓ Branch 1 taken 4133647 times.
78539293 for (int i = 0; i < ZC_CONTROL_STATES; i++)
4498 74405646 down_control_states[i] = raw_control_state[i];
4499 4133647 }
4500
4501
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 19209276 times.
19209306 if (replay_is_active())
4502 {
4503
2/2
✓ Branch 0 taken 1524381 times.
✓ Branch 1 taken 17684895 times.
19209276 if (replay_version_check(3))
4504 17684895 replay_poll();
4505
4506
4/4
✓ Branch 0 taken 7457865 times.
✓ Branch 1 taken 11751411 times.
✓ Branch 2 taken 100535 times.
✓ Branch 3 taken 7357330 times.
19209276 if (replay_version_check(11) || replay_version_check(6, 8))
4507 11851946 replay_peek_input();
4508 19209276 }
4509
4510 19209306 process_enqueued_qr_changes();
4511
4512 19209306 load_control_called_this_frame = false;
4513
4514 19209306 poll_keyboard();
4515 19209306 update_keys();
4516
4517 19209306 ++frame;
4518
4519
2/2
✓ Branch 0 taken 130 times.
✓ Branch 1 taken 19209176 times.
19209306 if (replay_is_replaying())
4520 19209176 replay_do_cheats();
4521 19209306 syskeys();
4522
4523 // The mouse variables can change from the mouse thread at anytime during a frame,
4524 // so save the result at the start so that replaying is consistent.
4525 19209306 script_mouse_x = gui_mouse_x();
4526 19209306 script_mouse_y = gui_mouse_y();
4527 19209306 script_mouse_z = mouse_z;
4528 19209306 script_mouse_b = mouse_b;
4529
4530 // Cheats used via the System menu (called by syskeys) will call cheats_enqueue. syskeys
4531 // is called just above, and in the paused loop above, so the queue-and-defer-slightly
4532 // approach here means it doesn't matter which call adds the cheat.
4533 19209306 cheats_execute_queued();
4534
4535
2/2
✓ Branch 0 taken 130 times.
✓ Branch 1 taken 19209176 times.
19209306 if (replay_is_replaying())
4536 19209176 replay_peek_quit();
4537
2/2
✓ Branch 0 taken 19209235 times.
✓ Branch 1 taken 71 times.
19209306 if (GameFlags & GAMEFLAG_TRYQUIT)
4538 71 replay_step_quit(0);
4539
2/2
✓ Branch 0 taken 3327 times.
✓ Branch 1 taken 19205979 times.
19209306 if(allowF6Script)
4540 19205979 FFCore.runF6Engine();
4541
2/2
✓ Branch 0 taken 770 times.
✓ Branch 1 taken 19208536 times.
19209306 if (Quit)
4542 770 replay_step_quit(Quit);
4543
4544 #ifdef _WIN32
4545
4546 if(use_dwm_flush)
4547 {
4548 do_DwmFlush();
4549 }
4550
4551 #endif
4552
4553
2/2
✓ Branch 0 taken 219006 times.
✓ Branch 1 taken 18990300 times.
19209306 if(sfxcleanup)
4554 18990300 sfx_cleanup();
4555
4556 19209306 frame_timings_poll();
4557
4558 #ifdef __EMSCRIPTEN__
4559 // Yield the main thread back to the browser occasionally.
4560 if (is_headless())
4561 {
4562 static int rate = 10000;
4563 static int force_yield = rate;
4564 if (force_yield++ >= rate)
4565 {
4566 force_yield = 0;
4567 emscripten_sleep(0);
4568 }
4569 }
4570 #endif
4571
4572
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 19209206 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
19209306 if (zqtesting_mode && test_mode_auto_restart)
4573 {
4574 static auto last_write_time = fs::last_write_time(qstpath);
4575 static auto last_check = std::chrono::system_clock::now();
4576
4577 if (std::chrono::system_clock::now() - last_check > 200ms)
4578 {
4579 last_check = std::chrono::system_clock::now();
4580 auto write_time = fs::last_write_time(qstpath);
4581 if (last_write_time != write_time)
4582 {
4583 last_write_time = write_time;
4584 disableClickToFreeze = false;
4585 Quit = qRESET;
4586 replay_quit();
4587 }
4588 }
4589 }
4590 19210685 }
4591
4592 590 void zapout()
4593 {
4594 590 set_clip_rect(scrollbuf_old, 0, 0, scrollbuf_old->w, scrollbuf_old->h);
4595 590 blit(framebuf,scrollbuf_old,0,0,256,0,256,framebuf->h);
4596
4597 590 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4598 590 script_drawing_commands.Clear();
4599
4600 // zap out
4601
2/2
✓ Branch 0 taken 590 times.
✓ Branch 1 taken 14160 times.
14750 for(int32_t i=1; i<=24; i++)
4602 {
4603 14160 draw_fuzzy(i);
4604 14160 advanceframe(true);
4605
4606
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14160 times.
14160 if(Quit)
4607 {
4608 break;
4609 }
4610 14160 }
4611 590 }
4612
4613 588 void zapin()
4614 {
4615 588 FFCore.warpScriptCheck();
4616 588 draw_screen();
4617 588 set_clip_rect(scrollbuf_old, 0, 0, scrollbuf_old->w, scrollbuf_old->h);
4618 588 blit(framebuf,scrollbuf_old,0,0,256,0,256,framebuf->h);
4619
4620 // zap out
4621 588 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4622
2/2
✓ Branch 0 taken 588 times.
✓ Branch 1 taken 14112 times.
14700 for(int32_t i=24; i>=1; i--)
4623 {
4624 14112 draw_fuzzy(i);
4625 14112 advanceframe(true);
4626
4627
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14112 times.
14112 if(Quit)
4628 {
4629 break;
4630 }
4631 14112 }
4632 588 }
4633
4634
4635 240 void wavyout(bool showhero)
4636 {
4637 240 draw_screen(showhero);
4638
4639 240 BITMAP *wavebuf = create_bitmap_ex(8,288,framebuf->h);
4640 240 clear_to_color(wavebuf,0);
4641 240 blit(framebuf,wavebuf,0,0,16,0,framebuf->w,framebuf->h);
4642
4643 static PALETTE wavepal;
4644
4645 int32_t ofs;
4646 240 int32_t amplitude=8;
4647
4648 240 int32_t wavelength=4;
4649 240 int height = viewport.visible_height(show_bottom_8px);
4650 240 double palpos=0, palstep=4, palstop=126;
4651
4652 240 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4653
2/2
✓ Branch 0 taken 239 times.
✓ Branch 1 taken 10065 times.
10304 for(int32_t i=0; i<height; i+=wavelength)
4654 {
4655
2/2
✓ Branch 0 taken 2576640 times.
✓ Branch 1 taken 10065 times.
2586705 for(int32_t l=0; l<256; l++)
4656 {
4657 2576640 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4658 2576640 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4659 2576640 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4660 2576640 }
4661
4662 10065 palpos+=palstep;
4663
4664
1/2
✓ Branch 0 taken 10065 times.
✗ Branch 1 not taken.
10065 if(palpos>=0)
4665 {
4666 10065 hw_palette = &wavepal;
4667 10065 update_hw_pal = true;
4668 10065 }
4669 else
4670 {
4671 hw_palette = &RAMpal;
4672 update_hw_pal = true;
4673 }
4674
4675
2/2
✓ Branch 0 taken 1692680 times.
✓ Branch 1 taken 10065 times.
1702745 for(int32_t j=0; j+playing_field_offset<framebuf->h; j++)
4676 {
4677
2/2
✓ Branch 0 taken 433326080 times.
✓ Branch 1 taken 1692680 times.
435018760 for(int32_t k=0; k<256; k++)
4678 {
4679 433326080 ofs=0;
4680
4681
4/4
✓ Branch 0 taken 211292160 times.
✓ Branch 1 taken 222033920 times.
✓ Branch 2 taken 105646080 times.
✓ Branch 3 taken 105646080 times.
433326080 if((j<i)&&(j&1))
4682 {
4683 105646080 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/height))*amplitude);
4684 105646080 }
4685
4686 433326080 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4687 433326080 }
4688 1692680 }
4689
4690 10065 advanceframe(true);
4691
4692
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10064 times.
10065 if(Quit)
4693 1 break;
4694 10064 }
4695
4696 240 destroy_bitmap(wavebuf);
4697
4698 240 hw_palette = &RAMpal;
4699 240 update_hw_pal = true;
4700 240 }
4701
4702 237 void wavyin()
4703 {
4704 237 draw_screen();
4705
4706 237 BITMAP *wavebuf = create_bitmap_ex(8,288,framebuf->h);
4707 237 clear_to_color(wavebuf,0);
4708 237 blit(framebuf,wavebuf,0,0,16,0,framebuf->w,framebuf->h);
4709
4710 static PALETTE wavepal;
4711
4712 237 refreshpal=false;
4713 int32_t ofs;
4714 237 int32_t amplitude=8;
4715 237 int32_t wavelength=4;
4716 237 int height = viewport.visible_height(show_bottom_8px);
4717 237 double palpos=height, palstep=4, palstop=126;
4718
4719 237 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4720
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 9923 times.
10159 for(int32_t i=0; i<height; i+=wavelength)
4721 {
4722
2/2
✓ Branch 0 taken 2540288 times.
✓ Branch 1 taken 9923 times.
2550211 for(int32_t l=0; l<256; l++)
4723 {
4724 2540288 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4725 2540288 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4726 2540288 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4727 2540288 }
4728
4729 9923 palpos-=palstep;
4730
4731
1/2
✓ Branch 0 taken 9923 times.
✗ Branch 1 not taken.
9923 if(palpos>=0)
4732 {
4733 9923 hw_palette = &wavepal;
4734 9923 update_hw_pal = true;
4735 9923 }
4736 else
4737 {
4738 hw_palette = &RAMpal;
4739 update_hw_pal = true;
4740 }
4741
4742
2/2
✓ Branch 0 taken 1668824 times.
✓ Branch 1 taken 9923 times.
1678747 for(int32_t j=0; j+playing_field_offset<framebuf->h; j++)
4743 {
4744
2/2
✓ Branch 0 taken 427218944 times.
✓ Branch 1 taken 1668824 times.
428887768 for(int32_t k=0; k<256; k++)
4745 {
4746 427218944 ofs=0;
4747
4748
4/4
✓ Branch 0 taken 216170752 times.
✓ Branch 1 taken 211048192 times.
✓ Branch 2 taken 109355520 times.
✓ Branch 3 taken 106815232 times.
427218944 if((j<(height-1-i))&&(j&1))
4749 {
4750 106815232 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/height))*amplitude);
4751 106815232 }
4752
4753 427218944 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4754 427218944 }
4755 1668824 }
4756
4757 9923 advanceframe(true);
4758
4759
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9922 times.
9923 if(Quit)
4760 1 break;
4761 9922 }
4762
4763 237 destroy_bitmap(wavebuf);
4764
4765 237 hw_palette = &RAMpal;
4766 237 update_hw_pal = true;
4767 237 }
4768
4769 4604 void blackscr(int32_t fcnt,bool showsubscr)
4770 {
4771 4604 reset_pal_cycling();
4772 4604 script_drawing_commands.Clear();
4773
4774 4604 FFCore.warpScriptCheck();
4775 4604 bool showtime = game->should_show_time();
4776
2/2
✓ Branch 0 taken 4597 times.
✓ Branch 1 taken 137677 times.
142274 while(fcnt>0)
4777 {
4778 137677 clear_bitmap(framebuf);
4779
4780
2/2
✓ Branch 0 taken 59280 times.
✓ Branch 1 taken 78397 times.
137677 if(showsubscr)
4781 {
4782 78397 put_passive_subscr(framebuf,0,0,showtime,sspUP);
4783
4/4
✓ Branch 0 taken 70567 times.
✓ Branch 1 taken 7830 times.
✓ Branch 2 taken 1410 times.
✓ Branch 3 taken 69157 times.
78397 if(get_qr(qr_SCRIPTDRAWSINWARPS) || (get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_WHEN_GAME_IS_FROZEN)))
4784 {
4785 9240 do_script_draws(framebuf, origin_scr, 0, playing_field_offset);
4786 9240 }
4787 78397 }
4788
4789 137677 advanceframe(true);
4790
4791
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 137670 times.
137677 if(Quit)
4792 7 break;
4793
4794 137670 --fcnt;
4795 }
4796 4604 }
4797
4798 2877 void openscreen(int32_t shape)
4799 {
4800 2877 update_viewport();
4801 2877 is_opening_screen = true;
4802 2877 reset_pal_cycling();
4803 2877 black_opening_count=0;
4804
4805
3/4
✓ Branch 0 taken 528 times.
✓ Branch 1 taken 2349 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 528 times.
2877 if(COOLSCROLL || shape>-1)
4806 {
4807 2349 open_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4808 2349 return;
4809 }
4810 else
4811 {
4812 528 Hero.setDontDraw(true);
4813 528 show_subscreen_dmap_dots=false;
4814 528 show_subscreen_numbers=false;
4815 528 show_subscreen_life=false;
4816 }
4817
4818 528 int32_t x=128;
4819
4820 528 FFCore.warpScriptCheck();
4821
2/2
✓ Branch 0 taken 528 times.
✓ Branch 1 taken 42240 times.
42768 for(int32_t i=0; i<80; i++)
4822 {
4823 42240 draw_screen();
4824 42240 x=128-(((i*128/80)/8)*8);
4825
4826
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42240 times.
42240 if(x>0)
4827 {
4828 42240 rectfill(framebuf,0,playing_field_offset,x,(viewport.h - 1)+playing_field_offset,0);
4829 42240 rectfill(framebuf,viewport.w-x,playing_field_offset,255,(viewport.h - 1)+playing_field_offset,0);
4830 42240 }
4831
4832 42240 advanceframe(true);
4833
4834
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42240 times.
42240 if(Quit)
4835 {
4836 break;
4837 }
4838 42240 }
4839
4840 528 Hero.setDontDraw(false);
4841 528 show_subscreen_items=true;
4842 528 show_subscreen_dmap_dots=true;
4843 528 show_subscreen_numbers=true;
4844 528 show_subscreen_life=true;
4845 2877 }
4846
4847 15 void closescreen(int32_t shape)
4848 {
4849 15 is_opening_screen = false;
4850 15 reset_pal_cycling();
4851 15 black_opening_count=0;
4852
4853
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
15 if(COOLSCROLL || shape>-1)
4854 {
4855 15 close_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4856 15 return;
4857 }
4858 else
4859 {
4860 Hero.setDontDraw(true);
4861 show_subscreen_dmap_dots=false;
4862 show_subscreen_numbers=false;
4863 // show_subscreen_items=false;
4864 show_subscreen_life=false;
4865 }
4866
4867 int32_t x=128;
4868
4869 FFCore.warpScriptCheck();
4870 for(int32_t i=79; i>=0; --i)
4871 {
4872 draw_screen();
4873 x=128-(((i*128/80)/8)*8);
4874
4875 if(x>0)
4876 {
4877 rectfill(framebuf,0,playing_field_offset,x,(viewport.h - 1)+playing_field_offset,0);
4878 rectfill(framebuf,viewport.w-x,playing_field_offset,255,(viewport.h - 1)+playing_field_offset,0);
4879 }
4880
4881 advanceframe(true);
4882
4883 if(Quit)
4884 {
4885 break;
4886 }
4887 }
4888
4889 Hero.setDontDraw(false);
4890 show_subscreen_items=true;
4891 show_subscreen_dmap_dots=true;
4892 15 }
4893
4894 326 int32_t TriforceCount()
4895 {
4896 326 int32_t c=0;
4897
4898
2/2
✓ Branch 0 taken 2608 times.
✓ Branch 1 taken 326 times.
2934 for(int32_t i=1; i<=8; i++)
4899
2/2
✓ Branch 0 taken 496 times.
✓ Branch 1 taken 2112 times.
4720 if(game->lvlitems[i]&(1 << li_mcguffin))
4900 2112 ++c;
4901
4902 326 return c;
4903 }
4904
4905 int32_t onCustomGame()
4906 {
4907 auto save = get_unset_save_slot();
4908 if (!save)
4909 return D_CLOSE;
4910
4911 if (prompt_for_quest_path(save->header->qstpath))
4912 {
4913 save->header->qstpath = qstpath;
4914 return D_O_K;
4915 }
4916
4917 return D_CLOSE;
4918 }
4919
4920 int32_t onContinue()
4921 {
4922 return D_CLOSE;
4923 }
4924
4925 int32_t onThrottleFPS()
4926 {
4927 Throttlefps = !Throttlefps;
4928 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4929 return D_O_K;
4930 }
4931
4932 int32_t onWinPosSave()
4933 {
4934 SaveWinPos = !SaveWinPos;
4935 zc_set_config(cfg_sect,"save_window_position",(int32_t)SaveWinPos);
4936 return D_O_K;
4937 }
4938 int32_t onIntegerScaling()
4939 {
4940 scaleForceInteger = !scaleForceInteger;
4941 zc_set_config("zeldadx","scaling_force_integer",(int)scaleForceInteger);
4942 return D_O_K;
4943 }
4944 int32_t onStretchGame()
4945 {
4946 stretchGame = !stretchGame;
4947 zc_set_config("zeldadx","stretch_game_area",stretchGame?1:0);
4948 return D_O_K;
4949 }
4950
4951 int32_t onClickToFreeze()
4952 {
4953 ClickToFreeze = !ClickToFreeze;
4954 zc_set_config(cfg_sect,"clicktofreeze", (int32_t)ClickToFreeze);
4955 return D_O_K;
4956 }
4957
4958 int32_t OnSaveZCConfig()
4959 {
4960 if(jwin_alert3(
4961 "Save Configuration",
4962 "Are you sure that you wish to save your present configuration settings?",
4963 "This will overwrite your prior settings!",
4964 NULL,
4965 "&Yes",
4966 "&No",
4967 NULL,
4968 'y',
4969 'n',
4970 0,
4971 get_zc_font(font_lfont)) == 1)
4972 {
4973 save_game_configs();
4974 return D_O_K;
4975 }
4976 else return D_O_K;
4977 }
4978
4979 int32_t OnnClearQuestDir()
4980 {
4981 auto current_path = fs::current_path() / "quests";
4982 if(jwin_alert3(
4983 "Clear Current Directory Cache",
4984 "Are you sure that you wish to reset where ZC Player looks for quests?",
4985 fmt::format("The new directory will be: {}", current_path.string()).c_str(),
4986 NULL,
4987 "&Yes",
4988 "&No",
4989 NULL,
4990 'y',
4991 'n',
4992 0,
4993 get_zc_font(font_lfont)) == 1)
4994 {
4995 zc_set_config("zeldadx","quest_dir","quests");
4996 flush_config_file();
4997 strcpy(qstdir,"quests");
4998 #ifdef __EMSCRIPTEN__
4999 em_sync_fs();
5000 #endif
5001 return D_O_K;
5002 }
5003 else return D_O_K;
5004 }
5005
5006 int32_t onConsole()
5007 {
5008 if ( !console_enabled )
5009 {
5010 AlertDialog("ZC Console",
5011 "Open the ZC Console?"
5012 "\nThis will display any messages logged by scripts,"
5013 " including errors.",
5014 [&](bool ret,bool)
5015 {
5016 if(ret)
5017 {
5018 FFCore.ZScriptConsole(true);
5019 }
5020 }).show();
5021 return D_O_K;
5022 }
5023 else
5024 {
5025 FFCore.ZScriptConsole(false);
5026 return D_O_K;
5027 }
5028 }
5029
5030 int32_t onClrConsoleOnReload()
5031 {
5032 clearConsoleOnReload = !clearConsoleOnReload;
5033 zc_set_config("CONSOLE","clear_console_on_reload",clearConsoleOnReload?1:0);
5034 return D_O_K;
5035 }
5036 int32_t onClrConsoleOnLoad()
5037 {
5038 clearConsoleOnLoad = !clearConsoleOnLoad;
5039 zc_set_config("CONSOLE","clear_console_on_load",clearConsoleOnLoad?1:0);
5040 return D_O_K;
5041 }
5042
5043
5044 int32_t onFrameSkip()
5045 {
5046 FrameSkip = !FrameSkip;
5047 return D_O_K;
5048 }
5049
5050 int32_t onSaveDragResize()
5051 {
5052 SaveDragResize = !SaveDragResize;
5053 zc_set_config(cfg_sect,"save_drag_resize",(int32_t)SaveDragResize);
5054 return D_O_K;
5055 }
5056
5057 int32_t onDragAspect()
5058 {
5059 DragAspect = !DragAspect;
5060 zc_set_config(cfg_sect,"drag_aspect",(int32_t)DragAspect);
5061 return D_O_K;
5062 }
5063
5064 int32_t onTransLayers()
5065 {
5066 TransLayers = !TransLayers;
5067 zc_set_config(cfg_sect,"translayers",(int32_t)TransLayers);
5068 return D_O_K;
5069 }
5070
5071 int32_t onNESquit()
5072 {
5073 NESquit = !NESquit;
5074 zc_set_config(cfg_sect,"fastquit",(int32_t)NESquit);
5075 return D_O_K;
5076 }
5077
5078 int32_t onVolKeys()
5079 {
5080 volkeys = !volkeys;
5081 zc_set_config(sfx_sect,"volkeys",(int32_t)volkeys);
5082 return D_O_K;
5083 }
5084
5085 int32_t onShowFPS()
5086 {
5087 ShowFPS = !ShowFPS;
5088 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
5089 return D_O_K;
5090 }
5091
5092 int32_t onShowTime()
5093 {
5094 ShowGameTime = !ShowGameTime;
5095 zc_set_config(cfg_sect,"showtime",ShowGameTime);
5096 return D_O_K;
5097 }
5098
5099 2266694568 bool is_Fkey(int32_t k)
5100 {
5101
2/2
✓ Branch 0 taken 230511312 times.
✓ Branch 1 taken 2036183256 times.
2266694568 switch(k)
5102 {
5103 case KEY_F1:
5104 case KEY_F2:
5105 case KEY_F3:
5106 case KEY_F4:
5107 case KEY_F5:
5108 case KEY_F6:
5109 case KEY_F7:
5110 case KEY_F8:
5111 case KEY_F9:
5112 case KEY_F10:
5113 case KEY_F11:
5114 case KEY_F12:
5115 230511312 return true;
5116 }
5117
5118 2036183256 return false;
5119 2266694568 }
5120
5121 void kb_getkey(DIALOG *d);
5122
5123 //Used by all keyboard key settings dialogues.
5124 void kb_clearjoystick(DIALOG *d)
5125 {
5126 d->flags|=D_SELECTED;
5127
5128 jwin_button_proc(MSG_DRAW,d,0);
5129 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5130 // text_mode(vc(11));
5131 textout_centre_ex(screen, font, "Press any key to clear", gui_bmp->w/2, gui_bmp->h/2 - 8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5132 textout_centre_ex(screen, font, "ESC to cancel", gui_bmp->w/2, gui_bmp->h/2, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5133
5134 update_hw_screen();
5135
5136 clear_keybuf();
5137 int32_t k = next_press_key();
5138 clear_keybuf();
5139
5140 //shnarf
5141 //47=f1
5142 //59=esc
5143 // if(k>0 && k<123 && !((k>46)&&(k<60)))
5144 // *((int32_t*)d->dp3) = k;
5145 if ( k != 59 ) *((int32_t*)d->dp3) = 0;
5146
5147
5148 d->flags&=~D_SELECTED;
5149 }
5150
5151 //Clears key to 0.
5152 //Used by all keyboard key settings dialogues.
5153 void kb_clearkey(DIALOG *d);
5154
5155 int32_t d_j_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5156 {
5157 switch(msg)
5158 {
5159 case MSG_KEY:
5160 case MSG_CLICK:
5161
5162 kb_clearjoystick(d);
5163
5164 while(gui_mouse_b())
5165 {
5166 clear_keybuf();
5167 rest(1);
5168 }
5169
5170 return D_REDRAW;
5171 }
5172
5173 return jwin_button_proc(msg,d,c);
5174 }
5175
5176 int32_t d_kbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5177 //Only used in keyboard settings dialogues to clear keys.
5178 int32_t d_k_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5179
5180 int32_t j_getbtn(DIALOG *d)
5181 {
5182 d->flags|=D_SELECTED;
5183 jwin_button_proc(MSG_DRAW,d,0);
5184 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5185 // text_mode(vc(11));
5186 int32_t y = screen->h/2 - 12;
5187 textout_centre_ex(screen, font, "Press a button", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5188 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5189 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5190
5191 update_hw_screen();
5192
5193 int32_t b = next_joy_input(true);
5194 if (b == -2)
5195 return D_CLOSE;
5196
5197 if(b>=0)
5198 *((int32_t*)d->dp3) = b;
5199
5200 d->flags&=~D_SELECTED;
5201
5202 return D_O_K;
5203 }
5204
5205 void j_getstick(DIALOG *d)
5206 {
5207 d->flags|=D_SELECTED;
5208 jwin_button_proc(MSG_DRAW,d,0);
5209 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5210 // text_mode(vc(11));
5211 int32_t y = screen->h/2 - 12;
5212 textout_centre_ex(screen, font, "Move a stick (or DPAD)", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5213 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5214 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5215
5216 update_hw_screen();
5217
5218 int32_t b = next_joy_input(false);
5219
5220 if(b>=0)
5221 *((int32_t*)d->dp3) = b;
5222
5223 d->flags&=~D_SELECTED;
5224 }
5225
5226 int32_t d_jbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5227 {
5228 switch(msg)
5229 {
5230 case MSG_KEY:
5231 case MSG_CLICK:
5232
5233 int ret = j_getbtn(d);
5234 if (ret != D_O_K)
5235 return ret;
5236
5237 while(gui_mouse_b()) {
5238 rest(1);
5239 clear_keybuf();
5240 }
5241
5242 return D_REDRAW;
5243 }
5244
5245 return jwin_button_proc(msg,d,c);
5246 }
5247
5248 int32_t d_jstick_proc(int32_t msg,DIALOG *d,int32_t c)
5249 {
5250 switch(msg)
5251 {
5252 case MSG_KEY:
5253 case MSG_CLICK:
5254
5255 j_getstick(d);
5256
5257 while(gui_mouse_b()) {
5258 rest(1);
5259 clear_keybuf();
5260 }
5261
5262 return D_REDRAW;
5263 }
5264
5265 return jwin_button_proc(msg,d,c);
5266 }
5267
5268 //shnarf
5269 extern const char *key_str[];
5270 std::string get_keystr(int key);
5271
5272 const char *pan_str[4] = { " MONO", " 1/2", " 3/4", " FULL" };
5273
5274 static char str_a[80],str_b[80],str_s[80],str_m[80],str_l[80],str_r[80],str_p[80],str_ex1[80],str_ex2[80],str_ex3[80],str_ex4[80],
5275 str_leftmod1[80],str_leftmod2[80],str_rightmod1[80],str_rightmod2[80], str_left[80], str_right[80], str_up[80], str_down[80],
5276 str_primary_stick[80], str_secondary_stick[80];
5277
5278 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c)
5279 {
5280 //these are here to bypass compiler warnings about unused arguments
5281 c=c;
5282
5283 if (d->w == 1)
5284 {
5285 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
5286 {
5287 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
5288 return D_CLOSE;
5289 }
5290 }
5291
5292 if(msg==MSG_DRAW)
5293 {
5294 switch(d->w)
5295 {
5296 case 0:
5297 sprintf(str_a,"%03d\n%s",Akey,key_str[Akey]);
5298 sprintf(str_b,"%03d\n%s",Bkey,key_str[Bkey]);
5299 sprintf(str_s,"%03d\n%s",Skey,key_str[Skey]);
5300 sprintf(str_l,"%03d\n%s",Lkey,key_str[Lkey]);
5301 sprintf(str_r,"%03d\n%s",Rkey,key_str[Rkey]);
5302 sprintf(str_p,"%03d\n%s",Pkey,key_str[Pkey]);
5303 sprintf(str_ex1,"%03d\n%s",Exkey1,key_str[Exkey1]);
5304 sprintf(str_ex2,"%03d\n%s",Exkey2,key_str[Exkey2]);
5305 sprintf(str_ex3,"%03d\n%s",Exkey3,key_str[Exkey3]);
5306 sprintf(str_ex4,"%03d\n%s",Exkey4,key_str[Exkey4]);
5307 sprintf(str_up,"%03d\n%s",DUkey,key_str[DUkey]);
5308 sprintf(str_down,"%03d\n%s",DDkey,key_str[DDkey]);
5309 sprintf(str_left,"%03d\n%s",DLkey,key_str[DLkey]);
5310 sprintf(str_right,"%03d\n%s",DRkey,key_str[DRkey]);
5311 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5312 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5313 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5314 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5315 break;
5316
5317 case 1:
5318 sprintf(str_a,"%03d\n%s",Abtn,joybtn_name(Abtn));
5319 sprintf(str_b,"%03d\n%s",Bbtn,joybtn_name(Bbtn));
5320 sprintf(str_s,"%03d\n%s",Sbtn,joybtn_name(Sbtn));
5321 sprintf(str_l,"%03d\n%s",Lbtn,joybtn_name(Lbtn));
5322 sprintf(str_r,"%03d\n%s",Rbtn,joybtn_name(Rbtn));
5323 sprintf(str_m,"%03d\n%s",Mbtn,joybtn_name(Mbtn));
5324 sprintf(str_p,"%03d\n%s",Pbtn,joybtn_name(Pbtn));
5325 sprintf(str_ex1,"%03d\n%s",Exbtn1,joybtn_name(Exbtn1));
5326 sprintf(str_ex2,"%03d\n%s",Exbtn2,joybtn_name(Exbtn2));
5327 sprintf(str_ex3,"%03d\n%s",Exbtn3,joybtn_name(Exbtn3));
5328 sprintf(str_ex4,"%03d\n%s",Exbtn4,joybtn_name(Exbtn4));
5329 sprintf(str_up,"%03d\n%s",DUbtn,joybtn_name(DUbtn));
5330 sprintf(str_down,"%03d\n%s",DDbtn,joybtn_name(DDbtn));
5331 sprintf(str_left,"%03d\n%s",DLbtn,joybtn_name(DLbtn));
5332 sprintf(str_right,"%03d\n%s",DRbtn,joybtn_name(DRbtn));
5333 sprintf(str_primary_stick,"%03d\n%s",js_stick_1_x_stick,joystick_name(js_stick_1_x_stick));
5334 sprintf(str_secondary_stick,"%03d\n%s",js_stick_2_x_stick,joystick_name(js_stick_2_x_stick));
5335 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5336 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5337 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5338 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5339 break;
5340
5341 case 2:
5342 sprintf(str_a," %3d",midi_volume);
5343 sprintf(str_l," %3d",emusic_volume);
5344 sprintf(str_r," %3d",sfx_volume);
5345 strcpy(str_s,pan_str[pan_style]);
5346 sprintf(str_leftmod1,"%3d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5347 sprintf(str_leftmod2,"%3d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5348 sprintf(str_rightmod1,"%3d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5349 sprintf(str_rightmod2,"%3d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5350 break;
5351 }
5352 }
5353
5354 return D_O_K;
5355 }
5356
5357 int32_t set_vol(void *dp3, int32_t d2)
5358 {
5359 switch(((int32_t*)dp3)[0])
5360 {
5361 case 0:
5362 midi_volume = zc_min(d2<<3,255);
5363 break;
5364
5365 case 1:
5366 digi_volume = zc_min(d2<<3,255);
5367 break;
5368
5369 case 2:
5370 emusic_volume = zc_min(d2<<3,255);
5371 break;
5372
5373 case 3:
5374 sfx_volume = zc_min(d2<<3,255);
5375 break;
5376 }
5377
5378 // text_mode(vc(11));
5379 textprintf_right_ex(screen,get_zc_font(font_lfont_l), ((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]," %3d",zc_min(d2<<3,255));
5380 return D_O_K;
5381 }
5382
5383 int32_t set_pan(void *dp3, int32_t d2)
5384 {
5385 pan_style = vbound(d2,0,3);
5386 // text_mode(vc(11));
5387 textout_right_ex(screen,get_zc_font(font_lfont_l), pan_str[pan_style],((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5388 return D_O_K;
5389 }
5390
5391 static int32_t gamepad_joys_list[] =
5392 {
5393 61,
5394 -1
5395 };
5396
5397 static int32_t gamepad_btn_list[] =
5398 {
5399 6,
5400 7,8,9,10,11,12,13,14,15,16,17,
5401 18,19,20,21,22,23,24,25,26,27,28,
5402 29,30,31,32,33,34,35,36,37,38,39,
5403 -1
5404 };
5405
5406 static int32_t gamepad_dirs_list[] =
5407 {
5408 40,41,42,43,
5409 44,45,46,47,
5410 48,49,50,51,
5411 52,53,54,55,
5412 56,57,58,59,
5413 60,
5414 -1
5415 };
5416
5417 static TABPANEL gamepad_tabs[] =
5418 {
5419 // (text)
5420 { (char *)"Controllers", D_SELECTED, gamepad_joys_list, 0, NULL },
5421 { (char *)"Buttons", 0, gamepad_btn_list, 0, NULL },
5422 { (char *)"Directions", 0, gamepad_dirs_list, 0, NULL },
5423 { NULL, 0, NULL, 0, NULL }
5424 };
5425
5426 const char *joy_list(int32_t index, int32_t *list_size)
5427 {
5428 if (index == -1)
5429 {
5430 *list_size = al_get_num_joysticks();
5431 return NULL;
5432 }
5433
5434 ALLEGRO_JOYSTICK* joy = al_get_joystick(index);
5435 if (!joy)
5436 {
5437 return "?";
5438 }
5439
5440 return al_get_joystick_name(joy);
5441 }
5442
5443 429 static ListData joy__list(joy_list, &font);
5444
5445 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c)
5446 {
5447 int32_t d2 = d->d2;
5448 int32_t ret = jwin_droplist_proc(msg,d,c);
5449
5450 if(d2!=d->d2)
5451 {
5452 joystick_index = d->d2;
5453 ret |= D_REDRAW_ALL;
5454 }
5455
5456 return ret;
5457 }
5458
5459 static DIALOG gamepad_dlg[] =
5460 {
5461 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5462 { jwin_win_proc, 8, 24, 304, 256, 0, 0, 0, D_EXIT, 0, 0, (void *) "Gamepad Controls", NULL, NULL },
5463 { jwin_tab_proc, 8+4, 24+23,304-8,256-52,vc(0), vc(15), 0, 0, 0, 0, (void *) gamepad_tabs, NULL, (void *)gamepad_dlg },
5464 { d_stringloader, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5465 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5466 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5467 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5468 // 6
5469 { d_dummy_proc, 14, 61, 294, 192, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5470 // 7
5471 { jwin_ctext_proc, 92, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5472 { jwin_ctext_proc, 92, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5473 { jwin_ctext_proc, 92, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5474 { jwin_ctext_proc, 92, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5475 { jwin_ctext_proc, 92, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5476 { jwin_ctext_proc, 237, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5477 { jwin_ctext_proc, 237, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5478 { jwin_ctext_proc, 237, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5479 { jwin_ctext_proc, 237, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5480 { jwin_ctext_proc, 237, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5481 { jwin_ctext_proc, 92, 244-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_m, NULL, NULL },
5482 // 18
5483 { d_jbutton_proc, 22, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Abtn},
5484 { d_jbutton_proc, 22, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bbtn},
5485 { d_jbutton_proc, 22, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Sbtn},
5486 { d_jbutton_proc, 22, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exbtn1},
5487 { d_jbutton_proc, 22, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exbtn3},
5488 { d_jbutton_proc, 167, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lbtn},
5489 { d_jbutton_proc, 167, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rbtn},
5490 { d_jbutton_proc, 167, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pbtn},
5491 { d_jbutton_proc, 167, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exbtn2},
5492 { d_jbutton_proc, 167, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exbtn4},
5493 { d_jbutton_proc, 22, 242-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Menu", NULL, &Mbtn},
5494 // 29
5495 { d_j_clearbutton_proc, 22+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Abtn},
5496 { d_j_clearbutton_proc, 22+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bbtn},
5497 { d_j_clearbutton_proc, 22+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Sbtn},
5498 { d_j_clearbutton_proc, 22+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn1},
5499 { d_j_clearbutton_proc, 22+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn3},
5500 { d_j_clearbutton_proc, 167+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lbtn},
5501 { d_j_clearbutton_proc, 167+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rbtn},
5502 { d_j_clearbutton_proc, 167+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pbtn},
5503 { d_j_clearbutton_proc, 167+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn2},
5504 { d_j_clearbutton_proc, 167+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn4},
5505 { d_j_clearbutton_proc, 22+91, 242-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Mbtn},
5506 // 40
5507 { jwin_frame_proc, 14, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5508 { jwin_frame_proc, 159, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5509 { jwin_text_proc, 30, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5510 { jwin_text_proc, 175, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5511 // 44
5512 { jwin_text_proc, 92, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5513 { jwin_text_proc, 92, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5514 { jwin_text_proc, 237, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5515 { jwin_text_proc, 237, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5516 // 48
5517 { d_jbutton_proc, 22, 82, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUbtn },
5518 { d_jbutton_proc, 22, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDbtn },
5519 { d_jbutton_proc, 167, 82, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLbtn },
5520 { d_jbutton_proc, 167, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRbtn },
5521 // 52
5522 { d_j_clearbutton_proc, 22+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUbtn},
5523 { d_j_clearbutton_proc, 22+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDbtn},
5524 { d_j_clearbutton_proc, 167+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLbtn},
5525 { d_j_clearbutton_proc, 167+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRbtn},
5526 // 56
5527 { jwin_check_proc, 22, 150, 147, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "Primary: Use Analog Stick (Ignore above and use below instead)", NULL, NULL },
5528 { d_jstick_proc, 22, 165, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Primary", NULL, &js_stick_1_x_stick },
5529 { d_jstick_proc, 22, 195, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Secondary", NULL, &js_stick_2_x_stick },
5530 { jwin_text_proc, 90, 165, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_primary_stick, NULL, NULL },
5531 { jwin_text_proc, 90, 195, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_secondary_stick, NULL, NULL },
5532
5533 // 61
5534 { d_joylist_proc, 22, 62, 150, 16, 0, 0, 0, 0, 0, 0, (void *) &joy__list, NULL, NULL },
5535
5536 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5537 };
5538
5539 static int32_t keyboard_keys_list[] =
5540 {
5541 6,7,8,9,10,
5542 11,12,13,14,15,16,17,18,19,20,
5543 21,22,23,24,25,26,27,28,29,30,
5544 31,32,33,34,35,36,37,38,39,40,
5545 -1
5546 };
5547
5548 static int32_t keyboard_dirs_list[] =
5549 {
5550 41,42,43,44,
5551 45,46,47,48,
5552 49,50,51,52,
5553 53,54,55,56,
5554 -1
5555 };
5556
5557 static int32_t keyboard_mods_list[] =
5558 {
5559 57,58,59,60,
5560 61,62,63,64,
5561 65,66,67,68,
5562 69,70,71,72,
5563 -1
5564 };
5565
5566 static TABPANEL keyboard_control_tabs[] =
5567 {
5568 // (text)
5569 { (char *)"Keys", D_SELECTED, keyboard_keys_list, 0, NULL },
5570 { (char *)"Directions", 0, keyboard_dirs_list, 0, NULL },
5571 { (char *)"Cheat Mods", 0, keyboard_mods_list, 0, NULL },
5572 { NULL, 0, NULL, 0, NULL }
5573 };
5574
5575 static DIALOG keyboard_control_dlg[] =
5576 {
5577 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5578 { jwin_win_proc, 8, 39, 304, 240, 0, 0, 0, D_EXIT, 0, 0, (void *) "Keyboard Controls", NULL, NULL },
5579 { jwin_tab_proc, 8+4, 39+23,304-8,240-56,vc(0), vc(15), 0, 0, 0, 0, (void *) keyboard_control_tabs, NULL, (void *)keyboard_control_dlg },
5580 { d_stringloader, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5581 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5582 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5583 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5584 // Keys
5585 // 6
5586 { jwin_frame_proc, 14, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5587 { jwin_frame_proc, 158, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5588 { jwin_frame_proc, 14, 181, 292, 67, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5589 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Standard", NULL, NULL },
5590 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Extended", NULL, NULL },
5591 // 11
5592 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5593 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5594 { jwin_text_proc, 92-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5595 { jwin_text_proc, 92-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5596 { jwin_text_proc, 92-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5597 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5598 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5599 { jwin_text_proc, 237-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5600 { jwin_text_proc, 237-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5601 { jwin_text_proc, 237-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5602 // 21
5603 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Akey},
5604 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bkey},
5605 { d_kbutton_proc, 22, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Skey},
5606 { d_kbutton_proc, 22, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exkey1},
5607 { d_kbutton_proc, 22, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exkey3},
5608 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lkey},
5609 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rkey},
5610 { d_kbutton_proc, 167, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pkey},
5611 { d_kbutton_proc, 167, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exkey2},
5612 { d_kbutton_proc, 167, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exkey4},
5613 // 31
5614 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Akey},
5615 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bkey},
5616 { d_k_clearbutton_proc, 22+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Skey},
5617 { d_k_clearbutton_proc, 22+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey1},
5618 { d_k_clearbutton_proc, 22+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey3},
5619 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lkey},
5620 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rkey},
5621 { d_k_clearbutton_proc, 167+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pkey},
5622 { d_k_clearbutton_proc, 167+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey2},
5623 { d_k_clearbutton_proc, 167+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey4},
5624 // Dirs
5625 // 41
5626 { jwin_frame_proc, 14, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5627 { jwin_frame_proc, 159, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5628 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5629 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5630 // 45
5631 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5632 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5633 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5634 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5635 // 49
5636 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUkey},
5637 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDkey},
5638 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLkey},
5639 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRkey},
5640 // 53
5641 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUkey},
5642 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDkey},
5643 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLkey},
5644 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRkey},
5645 // Mods
5646 // 57
5647 { jwin_frame_proc, 14, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5648 { jwin_frame_proc, 158, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5649 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Left", NULL, NULL },
5650 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Right", NULL, NULL },
5651 // 61
5652 { jwin_text_proc, 92-26, 101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod1, NULL, NULL },
5653 { jwin_text_proc, 92-26, 129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod1, NULL, NULL },
5654 { jwin_text_proc, 237-4-22,101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod2, NULL, NULL },
5655 { jwin_text_proc, 237-4-22,129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod2, NULL, NULL },
5656 // 65
5657 { d_kbutton_proc, 22, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[0]},
5658 { d_kbutton_proc, 22, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[2]},
5659 { d_kbutton_proc, 167, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[1]},
5660 { d_kbutton_proc, 167, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[3]},
5661 // 69
5662 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[0]},
5663 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[2]},
5664 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[1]},
5665 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[3]},
5666 // 73
5667 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5668 };
5669
5670 int32_t midi_dp[3] = {0,0,0};
5671 int32_t emus_dp[3] = {2,0,0};
5672 int32_t sfx_dp[3] = {3,0,0};
5673 int32_t pan_dp[3] = {0,0,0};
5674
5675 static DIALOG sound_dlg[] =
5676 {
5677 //(dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5678 429 { jwin_win_proc, 0, 0, 320, 178, 0, 0, 0, D_EXIT, 0, 0, (void *) "Sound Settings", NULL, NULL },
5679 429 { d_stringloader, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5680 429 { jwin_button_proc, 58, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5681 429 { jwin_button_proc, 138, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5682 429 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5683 429 { jwin_frame_proc, 10, 28, 300, 112, 0, 0, 0, 0, FR_ETCHED, 0, NULL, NULL, NULL },
5684 429 { jwin_rtext_proc, 190, 40, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_a, NULL, NULL },
5685 429 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5686 429 { jwin_rtext_proc, 190, 56, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_l, NULL, NULL },
5687 429 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5688 // 10
5689 429 { jwin_rtext_proc, 190, 72, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_r, NULL, NULL },
5690 429 { jwin_rtext_proc, 190, 88, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_s, NULL, NULL },
5691 429 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5692 429 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5693 429 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5694 429 { jwin_slider_proc, 196, 40, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, midi_dp },
5695 429 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5696 429 { jwin_slider_proc, 196, 56, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, emus_dp },
5697 429 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5698 429 { jwin_slider_proc, 196, 72, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, sfx_dp },
5699 //20
5700 429 { jwin_slider_proc, 196, 88, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 3, 0, NULL, (void *) set_pan, pan_dp },
5701 429 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5702 429 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5703 429 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5704 429 { jwin_text_proc, 17, 40, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "MIDI Volume", NULL, NULL },
5705 429 { jwin_text_proc, 17, 56, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Music Volume (Enhanced Music)", NULL, NULL },
5706 429 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5707 429 { jwin_text_proc, 17, 72, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Volume", NULL, NULL },
5708 429 { jwin_text_proc, 17, 88, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Pan", NULL, NULL },
5709 429 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5710 //30
5711 429 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5712 429 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5713 429 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5714 };
5715
5716 char zc_builddate[80];
5717 char zc_aboutstr[80];
5718
5719 static DIALOG about_dlg[] =
5720 {
5721 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5722 { jwin_win_proc, 68, 52, 184, 154, 0, 0, 0, D_EXIT, 0, 0, (void *) "About", NULL, NULL },
5723 { jwin_button_proc, 140, 176, 41, 21, vc(14), 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5724 { jwin_ctext_proc, 160, 84, 0, 8, vc(0), vc(11), 0, 0, 0, 0, zc_aboutstr, NULL, NULL },
5725 { jwin_ctext_proc, 160, 92, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5726 { jwin_ctext_proc, 160, 100, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, zc_builddate, NULL, NULL },
5727 { jwin_text_proc, 88, 124, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Coded by:", NULL, NULL },
5728 { jwin_text_proc, 88, 132, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Phantom Menace", NULL, NULL },
5729 { jwin_text_proc, 88, 144, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Produced by:", NULL, NULL },
5730 { jwin_text_proc, 88, 152, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Armageddon Games", NULL, NULL },
5731 { jwin_frame_proc, 80, 117, 160, 50, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5732 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5733 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5734 };
5735
5736
5737 static DIALOG quest_dlg[] =
5738 {
5739 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5740 { jwin_win_proc, 68, 25, 184, 190, 0, 0, 0, D_EXIT, 0, 0, (void *) "Quest Info", NULL, NULL },
5741 { jwin_edit_proc, 84, 54, 152, 16, 0, 0, 0, D_READONLY, 100, 0, NULL, NULL, NULL },
5742 { jwin_text_proc, 89, 84, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
5743 { jwin_text_proc, 152, 84, 24, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5744 { jwin_text_proc, 89, 94, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Version:", NULL, NULL },
5745 { jwin_text_proc, 160, 94, 64, 8, vc(7), vc(11), 0, 0, 0, 0, header_version_nul_term, NULL, NULL },
5746 { jwin_text_proc, 89, 104, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "ZQ Version:", NULL, NULL },
5747 { jwin_text_proc, 130, 104, 64, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5748 { jwin_text_proc, 84, 126, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Title:", NULL, NULL },
5749 { jwin_textbox_proc, 84, 136, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.title, NULL, NULL },
5750 { jwin_text_proc, 84, 168, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Author:", NULL, NULL },
5751 { jwin_textbox_proc, 84, 178, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.author, NULL, NULL },
5752 { jwin_frame_proc, 84, 79, 152, 38, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5753 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5754 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5755 };
5756
5757 static DIALOG triforce_dlg[] =
5758 {
5759 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
5760 { jwin_win_proc, 72, 64, 177, 105, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Triforce Pieces", NULL, NULL },
5761 // 1
5762 { jwin_check_proc, 129, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "1", NULL, NULL },
5763 { jwin_check_proc, 129, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "2", NULL, NULL },
5764 { jwin_check_proc, 129, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "3", NULL, NULL },
5765 { jwin_check_proc, 129, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "4", NULL, NULL },
5766 { jwin_check_proc, 172, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "5", NULL, NULL },
5767 { jwin_check_proc, 172, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "6", NULL, NULL },
5768 { jwin_check_proc, 172, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "7", NULL, NULL },
5769 { jwin_check_proc, 172, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "8", NULL, NULL },
5770 // 9
5771 { jwin_button_proc, 90, 144, 61, 21, vc(0), vc(11), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
5772 { jwin_button_proc, 170, 144, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5773 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5774 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5775 };
5776
5777 int32_t onToggleRecordingNewSaves()
5778 {
5779 if (zc_get_config("zeldadx", "replay_new_saves", false))
5780 {
5781 zc_set_config("zeldadx", "replay_new_saves", false);
5782 }
5783 else
5784 {
5785 zc_set_config("zeldadx", "replay_new_saves", true);
5786 jwin_alert("Recording", "Newly created saves will be recorded and written to a replay file.",
5787 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5788 }
5789 return D_O_K;
5790 }
5791
5792 #ifdef HAS_CURL
5793 int32_t onToggleAutoUploadReplays()
5794 {
5795 if (zc_get_config("zeldadx", "replay_upload", false))
5796 {
5797 zc_set_config("zeldadx", "replay_upload", false);
5798 }
5799 else
5800 {
5801 zc_set_config("zeldadx", "replay_upload", true);
5802 jwin_alert("Replays", "Replays will be automatically uploaded. This helps development by",
5803 " preventing bugs and simplifying bug reports.",
5804 "Upload will happen no more than once a week when closing ZC",
5805 "OK",NULL,13,27,get_zc_font(font_lfont));
5806
5807 if (!zc_get_config("zeldadx", "replay_new_saves", false))
5808 onToggleRecordingNewSaves();
5809 }
5810 return D_O_K;
5811 }
5812
5813 int32_t onUploadReplays()
5814 {
5815 if(jwin_alert3(
5816 "Upload replays",
5817 "Upload your replays now to assist in development?",
5818 NULL,
5819 NULL,
5820 "&Yes",
5821 "&No",
5822 NULL,
5823 'y',
5824 'n',
5825 0,
5826 get_zc_font(font_lfont)) == 1)
5827 {
5828 int num_uploaded = replay_upload();
5829 jwin_alert("Upload replays", fmt::format("Uploaded {} replays", num_uploaded).c_str(),
5830 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5831 }
5832 return D_O_K;
5833 }
5834
5835 int32_t onClearUploadCache()
5836 {
5837 if(jwin_alert3(
5838 "Upload replays",
5839 "Clear the upload cache?",
5840 "This simply deletes replays/state.json. There's no harm in doing this, but",
5841 "likely is not necessary.",
5842 "&Yes",
5843 "&No",
5844 NULL,
5845 'y',
5846 'n',
5847 0,
5848 get_zc_font(font_lfont)) == 1)
5849 {
5850 replay_upload_clear_cache();
5851 }
5852 return D_O_K;
5853 }
5854 #endif
5855
5856 int32_t onToggleSnapshotAllFrames()
5857 {
5858 replay_set_snapshot_all_frames(!replay_is_snapshot_all_frames());
5859 return D_O_K;
5860 }
5861
5862 int32_t onStopReplayOrRecord()
5863 {
5864 if (replay_is_replaying())
5865 {
5866 replay_quit();
5867 }
5868 else if (replay_get_mode() == ReplayMode::Record)
5869 {
5870 if (!replay_get_meta_bool("test_mode"))
5871 {
5872 jwin_alert("Recording", "You cannot stop recording a save file.",
5873 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5874 return D_CLOSE;
5875 }
5876
5877 if (jwin_alert("Stop Recording",
5878 "Save replay to disk and stop recording?",
5879 "This will stop the recording.",
5880 NULL,
5881 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5882 return D_CLOSE;
5883
5884 replay_save();
5885 replay_stop();
5886 }
5887 return D_O_K;
5888 }
5889
5890 static int32_t handle_on_load_replay(ReplayMode mode)
5891 {
5892 bool ctrl = CHECK_CTRL_CMD;
5893 if (Playing)
5894 {
5895 if (jwin_alert("Replay - Warning!",
5896 "Loading a replay will exit the current game.",
5897 "All unsaved progress will be lost.",
5898 "Do you wish to continue?",
5899 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5900 return D_CLOSE;
5901 }
5902
5903 std::string mode_string = replay_mode_to_string(mode);
5904 mode_string[0] = std::toupper(mode_string[0]);
5905
5906 std::string line_1 = "Select a replay file to play back.";
5907 std::string line_2 = "You won't be able to save, and it won't effect existing saves.";
5908 std::string line_3 = "You can stop the replay and take over manually any time.";
5909 if (mode == ReplayMode::Update)
5910 {
5911 line_1 = "Select a replay file to update.";
5912 line_2 = "WARNING: be sure to back up the zplay file";
5913 line_3 = "and verify that the updated replay works as expected!";
5914 }
5915
5916 if (jwin_alert(mode_string.c_str(),
5917 line_1.c_str(),
5918 line_2.c_str(),
5919 line_3.c_str(),
5920 "OK","Nevermind",13,27,get_zc_font(font_lfont)) == 1)
5921 {
5922 std::string replay_path = "replays/";
5923 if(ctrl && devpwd())
5924 replay_path = "../../tests/replays/";
5925 std::string prompt = fmt::format("Load Replay ({})", REPLAY_EXTENSION);
5926 if (auto result = prompt_for_existing_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5927 replay_path = *result;
5928 else
5929 return D_CLOSE;
5930
5931 replay_quit();
5932 load_replay_file_deferred(mode, replay_path);
5933 Quit = qRESET;
5934 return D_CLOSE;
5935 }
5936 return D_O_K;
5937 }
5938
5939 int32_t onLoadReplay()
5940 {
5941 return handle_on_load_replay(ReplayMode::Replay);
5942 }
5943
5944 int32_t onLoadReplayAssert()
5945 {
5946 return handle_on_load_replay(ReplayMode::Assert);
5947 }
5948
5949 int32_t onLoadReplayUpdate()
5950 {
5951 return handle_on_load_replay(ReplayMode::Update);
5952 }
5953
5954 int32_t onSaveReplay()
5955 {
5956 if (replay_get_mode() == ReplayMode::Record)
5957 {
5958 if (!replay_get_meta_bool("test_mode"))
5959 {
5960 if (jwin_alert("Save Replay",
5961 "This will save a copy of the replay up to this point.",
5962 "The official replay file will be untouched.",
5963 "Do you wish to continue?",
5964 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5965 {
5966 return D_CLOSE;
5967 }
5968
5969 std::string replay_path = replay_get_replay_path().string();
5970 std::string prompt = fmt::format("Save Replay ({})", REPLAY_EXTENSION);
5971 if (auto result = prompt_for_new_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5972 replay_path = *result;
5973 else
5974 return D_CLOSE;
5975
5976 if (fileexists(replay_path.c_str()))
5977 {
5978 jwin_alert("Save Replay", "You cannot overwrite an existing file.",
5979 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5980 return D_CLOSE;
5981 }
5982
5983 replay_save(replay_path);
5984 }
5985 else
5986 {
5987 replay_save();
5988 }
5989 }
5990 return D_O_K;
5991 }
5992
5993 enum
5994 {
5995 MENUID_REPLAY_RECORDNEW,
5996 MENUID_REPLAY_STOP,
5997 MENUID_REPLAY_SAVE,
5998 MENUID_REPLAY_SNAP_ALL,
5999 MENUID_REPLAY_AUTOUPLOAD,
6000 MENUID_REPLAY_UPLOAD,
6001 MENUID_REPLAY_CLEARUPLOADCACHE,
6002 };
6003
1/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
429 static NewMenu replay_menu
6004 5577 {
6005
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Record new saves", onToggleRecordingNewSaves, MENUID_REPLAY_RECORDNEW },
6006
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 {},
6007
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Stop replay", onStopReplayOrRecord, MENUID_REPLAY_STOP },
6008
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Load replay", onLoadReplay },
6009
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Load replay (assert)", onLoadReplayAssert },
6010
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Load replay (update)", onLoadReplayUpdate },
6011
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Save replay", onSaveReplay, MENUID_REPLAY_SAVE },
6012
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Snapshot all frames", onToggleSnapshotAllFrames, MENUID_REPLAY_SNAP_ALL },
6013 #ifdef HAS_CURL
6014
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 {},
6015
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Auto upload replays", onToggleAutoUploadReplays, MENUID_REPLAY_AUTOUPLOAD },
6016
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Upload replays", onUploadReplays, MENUID_REPLAY_UPLOAD },
6017
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Clear upload cache", onClearUploadCache, MENUID_REPLAY_CLEARUPLOADCACHE },
6018 #endif
6019 };
6020
6021 static DIALOG credits_dlg[] =
6022 {
6023 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6024 { jwin_win_proc, 40, 38, 241, 173, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "ZQuest Classic Credits", NULL, NULL },
6025 { jwin_frame_proc, 47, 65, 227, 115, vc(15), vc(1), 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
6026 { d_bitmap_proc, 49, 67, 222, 110, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6027 { jwin_button_proc, 140, 184, 41, 21, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6028 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6029 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6030 };
6031
6032 extern ListData dmap_list;
6033
6034 static DIALOG goto_dlg[] =
6035 {
6036 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6037 { jwin_win_proc, 48, 25, 205, 100, 0, 0, 0, D_EXIT, 0, 0, (void *) "Goto Location", NULL, NULL },
6038 { jwin_button_proc, 90, 176-78, 61, 21, vc(14), 0, 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6039 { jwin_button_proc, 170, 176-78, 61, 21, vc(14), 0, 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6040 { jwin_text_proc, 55, 129-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
6041 { jwin_droplist_proc, 88, 126-75, 160, 16, 0, 0, 0, 0, 0, 0, (void *) &dmap_list, NULL, NULL },
6042 { jwin_text_proc, 55, 149-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Screen:", NULL, NULL },
6043 { jwin_edit_proc, 132, 146-75, 91, 16, 0, 0, 0, 0, 2, 0, NULL, NULL, NULL },
6044 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6045 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6046 };
6047
6048 int32_t onGoTo()
6049 {
6050 bool music = false;
6051 music = music;
6052 sprintf(cheat_goto_screen_str,"%X",cheat_goto_screen);
6053
6054 goto_dlg[0].dp2=get_zc_font(font_lfont);
6055 goto_dlg[4].d2=cheat_goto_dmap;
6056 goto_dlg[6].dp=cheat_goto_screen_str;
6057
6058 clear_keybuf();
6059
6060 large_dialog(goto_dlg);
6061
6062 if(do_zqdialog(goto_dlg,4)==1)
6063 {
6064 int dmap = goto_dlg[4].d2;
6065 int screen = zc_xtoi(cheat_goto_screen_str);
6066 int adjusted_screen = screen + DMaps[dmap].xoff;
6067 if (adjusted_screen < 0 || adjusted_screen >= 128)
6068 {
6069 InfoDialog("Invalid screen", fmt::format("The screen {:02X} is out of bounds.", adjusted_screen)).show();
6070 }
6071 else
6072 {
6073 cheats_enqueue(Cheat::GoTo, dmap, screen);
6074 }
6075 };
6076
6077 return D_O_K;
6078 }
6079
6080 int32_t onGoToComplete()
6081 {
6082 if(!Playing)
6083 {
6084 return D_O_K;
6085 }
6086
6087 enter_sys_pal();
6088 music_pause();
6089 pause_all_sfx();
6090 onGoTo();
6091 eat_buttons();
6092
6093 zc_readrawkey(KEY_ESC);
6094
6095 exit_sys_pal();
6096 music_resume();
6097 resume_all_sfx();
6098 return D_O_K;
6099 }
6100
6101 int32_t onCredits()
6102 {
6103 return D_O_K;
6104 }
6105
6106 const char *midilist(int32_t index, int32_t *list_size)
6107 {
6108 if(index<0)
6109 {
6110 *list_size=0;
6111
6112 for(int32_t i=0; i<MAXMIDIS; i++)
6113 if(tunes[i].data)
6114 ++(*list_size);
6115
6116 return NULL;
6117 }
6118
6119 int32_t i=0,m=0;
6120
6121 while(m<=index && i<=MAXMIDIS)
6122 {
6123 if(tunes[i].data)
6124 ++m;
6125
6126 ++i;
6127 }
6128
6129 --i;
6130
6131 if(i==MAXMIDIS && m<index)
6132 return "(null)";
6133
6134 return tunes[i].title;
6135 }
6136
6137 /* ------- MIDI info stuff -------- */
6138
6139 char *text;
6140 midi_info *zmi;
6141 bool dialog_running;
6142 bool listening;
6143
6144 void get_info(int32_t index);
6145
6146 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c)
6147 {
6148 int32_t d2 = d->d2;
6149 int32_t ret = jwin_droplist_proc(msg,d,c);
6150
6151 if(d2!=d->d2)
6152 {
6153 get_info(d->d2);
6154 }
6155
6156 return ret;
6157 }
6158
6159 int32_t d_listen_proc(int32_t msg,DIALOG *d,int32_t c)
6160 {
6161 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6162
6163 int32_t ret = jwin_button_proc(msg,d,c);
6164
6165 if(ret == D_CLOSE)
6166 {
6167 // get current midi index
6168 int32_t index = (d+(d->d1))->d2;
6169 int32_t i=0, m=0;
6170
6171 while(m<=index && i<=MAXMIDIS)
6172 {
6173 if(tunes[i].data)
6174 ++m;
6175
6176 ++i;
6177 }
6178
6179 --i;
6180 jukebox(i);
6181 listening = true;
6182 ret = D_O_K;
6183 }
6184
6185 return ret;
6186 }
6187
6188 int32_t d_savemidi_proc(int32_t msg,DIALOG *d,int32_t c)
6189 {
6190 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6191
6192 int32_t ret = jwin_button_proc(msg,d,c);
6193
6194 if(ret == D_CLOSE)
6195 {
6196 // get current midi index
6197 int32_t index = (d+(d->d1))->d2;
6198 int32_t i=0, m=0;
6199
6200 while(m<=index && i<=MAXMIDIS)
6201 {
6202 if(tunes[i].data)
6203 ++m;
6204
6205 ++i;
6206 }
6207
6208 --i;
6209
6210 char title[40] = "Save MIDI: ";
6211 static EXT_LIST list[] =
6212 {
6213 { (char *)"MIDI files (*.mid)", (char *)"mid" },
6214 { NULL, NULL }
6215 };
6216
6217 strcpy(title+11, tunes[i].title);
6218 title[39] = '\0';
6219
6220 std::string fname;
6221 if (auto result = prompt_for_new_file(title, "", list, "tune.mid"))
6222 fname = *result;
6223 else
6224 goto done;
6225
6226 if(exists(fname.c_str()))
6227 {
6228 if(jwin_alert(title, fname.c_str(), "already exists.", "Overwrite it?", "&Yes","&No",'y','n',get_zc_font(font_lfont))==2)
6229 goto done;
6230 }
6231
6232 // save midi i
6233
6234 if (save_midi(fname.c_str(), tunes[i].data) != 0)
6235 jwin_alert(title, "Error saving MIDI to", fname.c_str(), NULL, "Darn", NULL,13,27,get_zc_font(font_lfont));
6236
6237 done:
6238 chop_path(fname.data());
6239 ret = D_REDRAW;
6240 }
6241
6242 return ret;
6243 }
6244
6245 429 static ListData midi_list(midilist, &font);
6246
6247 static DIALOG midi_dlg[] =
6248 {
6249 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6250 { jwin_win_proc, 8, 28, 304, 184, 0, 0, 0, D_EXIT, 0, 0, (void *) "MIDI Info", NULL, NULL },
6251 { jwin_text_proc, 32, 60, 40, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Tune:", NULL, NULL },
6252 { d_midilist_proc, 80, 56, 192, 16, 0, 0, 0, 0, 0, 0, (void *) &midi_list, NULL, NULL },
6253 { jwin_textbox_proc, 15, 80, 290, 96, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6254 { d_listen_proc, 24, 183, 72, 21, 0, 0, 'l', D_EXIT, -2, 0, (void *) "&Listen", NULL, NULL },
6255 { d_savemidi_proc, 108, 183, 72, 21, 0, 0, 's', D_EXIT, -3, 0, (void *) "&Save", NULL, NULL },
6256 { jwin_button_proc, 236, 183, 61, 21, 0, 0, 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
6257 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6258 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6259 };
6260
6261 void get_info(int32_t index)
6262 {
6263 int32_t i=0, m=0;
6264
6265 while(m<=index && i<=MAXMIDIS)
6266 {
6267 if(tunes[i].data)
6268 ++m;
6269
6270 ++i;
6271 }
6272
6273 --i;
6274
6275 if(i==MAXMIDIS && m<index)
6276 strcpy(text,"(null)");
6277 else
6278 {
6279 get_midi_info(tunes[i].data,zmi);
6280 get_midi_text(tunes[i].data,zmi,text);
6281 }
6282
6283 midi_dlg[0].dp2=get_zc_font(font_lfont);
6284 midi_dlg[3].dp = text;
6285 midi_dlg[3].d1 = midi_dlg[3].d2 = 0;
6286 midi_dlg[5].flags = (tunes[i].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6287
6288 if(dialog_running)
6289 {
6290 jwin_textbox_proc(MSG_DRAW,midi_dlg+3,0);
6291 d_savemidi_proc(MSG_DRAW,midi_dlg+5,0);
6292 }
6293 }
6294
6295 int32_t onMIDICredits()
6296 {
6297 text = (char*)malloc(4096);
6298 zmi = (midi_info*)malloc(sizeof(midi_info));
6299
6300 if(!text || !zmi)
6301 {
6302 jwin_alert(NULL,"Not enough memory",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6303 return D_O_K;
6304 }
6305
6306 bool do_pause_midi = midi_pos >= 0 && currmidi;
6307 auto restore_midi = currmidi;
6308 if(do_pause_midi)
6309 {
6310 paused_midi_pos = midi_pos;
6311 stop_midi();
6312 midi_suspended = midissuspHALTED;
6313 }
6314
6315 midi_dlg[0].dp2=get_zc_font(font_lfont);
6316 midi_dlg[2].d1 = 0;
6317 midi_dlg[2].d2 = 0;
6318 midi_dlg[4].flags = D_EXIT;
6319 midi_dlg[5].flags = (tunes[midi_dlg[2].d1].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6320
6321 listening = false;
6322 dialog_running=false;
6323 get_info(0);
6324
6325 dialog_running=true;
6326
6327 large_dialog(midi_dlg);
6328
6329 do_zqdialog(midi_dlg,0);
6330 dialog_running=false;
6331
6332 if(listening)
6333 music_stop();
6334
6335 if(do_pause_midi)
6336 {
6337 // TODO: this probably doesn't resume midis nicely when scrolling (or in some other inner-gameloop).
6338 midi_suspended = midissuspRESUME;
6339 currmidi = restore_midi;
6340 midi_pos = paused_midi_pos;
6341 }
6342
6343 if(text) free(text);
6344 if(zmi) free(zmi);
6345 return D_O_K;
6346 }
6347
6348 int32_t onAbout()
6349 {
6350 char buf1[80]={0};
6351 std::ostringstream oss;
6352 sprintf(buf1,"ZQuest Classic Player");
6353 oss << buf1 << '\n';
6354 sprintf(buf1,"Version: %s", getVersionString());
6355 oss << buf1 << '\n';
6356 sprintf(buf1,"Build Date: %s %s, %d at @ %s %s", dayextension(BUILDTM_DAY).c_str(), (char*)months[BUILDTM_MONTH], BUILDTM_YEAR, __TIME__, __TIMEZONE__);
6357 oss << buf1 << '\n';
6358
6359 InfoDialog("About ZC", oss.str()).show();
6360 return D_O_K;
6361 }
6362
6363 int32_t onQuest()
6364 {
6365 char fname[100];
6366 strcpy(fname, get_filename(qstpath));
6367 quest_dlg[0].dp2=get_zc_font(font_lfont);
6368 quest_dlg[1].dp = fname;
6369
6370 if(QHeader.quest_number==0)
6371 sprintf(str_a,"Custom");
6372 else
6373 sprintf(str_a,"%d",QHeader.quest_number);
6374
6375 sprintf(str_s,"%s",QHeader.getVerStr());
6376
6377 quest_dlg[11].d1 = quest_dlg[9].d1 = 0;
6378 quest_dlg[11].d2 = quest_dlg[9].d2 = 0;
6379
6380 large_dialog(quest_dlg);
6381
6382 do_zqdialog(quest_dlg, 0);
6383 return D_O_K;
6384 }
6385
6386 void call_vidmode_dlg();
6387 int32_t onVidMode()
6388 {
6389 call_vidmode_dlg();
6390 return D_O_K;
6391 }
6392
6393 #define addToHash(c,b,h) if(h->find(c ## key) == h->end()) \
6394 {(*h)[c ## key]=true;} else { if ( c ## key != 0 ) b = false;}
6395 //Added an extra statement, so that if the key is cleared to 0, the cleared
6396 //keybinding status need not be unique. -Z ( 1st April, 2019 )
6397
6398 void load_ukeys(int32_t* arr)
6399 {
6400 arr[ukey_a] = Akey;
6401 arr[ukey_b] = Bkey;
6402 arr[ukey_s] = Skey;
6403 arr[ukey_l] = Lkey;
6404 arr[ukey_r] = Rkey;
6405 arr[ukey_p] = Pkey;
6406 arr[ukey_ex1] = Exkey1;
6407 arr[ukey_ex2] = Exkey2;
6408 arr[ukey_ex3] = Exkey3;
6409 arr[ukey_ex4] = Exkey4;
6410 arr[ukey_du] = DUkey;
6411 arr[ukey_dd] = DDkey;
6412 arr[ukey_dl] = DLkey;
6413 arr[ukey_dr] = DRkey;
6414 arr[ukey_mod1a] = cheat_modifier_keys[0];
6415 arr[ukey_mod1b] = cheat_modifier_keys[1];
6416 arr[ukey_mod2a] = cheat_modifier_keys[2];
6417 arr[ukey_mod2b] = cheat_modifier_keys[3];
6418 };
6419
6420 static const char* ukey_names[] = {
6421 "A", "B", "Start", "L", "R", "Map",
6422 "Ex1", "Ex2", "Ex3", "Ex4", "Up", "Down",
6423 "Left", "Right", "Cheat Mod L1", "Cheat Mod L2",
6424 "Cheat Mod R1", "Cheat Mod R2",
6425 };
6426 std::string get_ukey_name(int32_t k)
6427 {
6428 if (k < num_ukey) return ukey_names[k];
6429 return "";
6430 }
6431
6432 int32_t onKeyboard()
6433 {
6434 int32_t a = Akey;
6435 int32_t b = Bkey;
6436 int32_t s = Skey;
6437 int32_t l = Lkey;
6438 int32_t r = Rkey;
6439 int32_t p = Pkey;
6440 int32_t ex1 = Exkey1;
6441 int32_t ex2 = Exkey2;
6442 int32_t ex3 = Exkey3;
6443 int32_t ex4 = Exkey4;
6444 int32_t du = DUkey;
6445 int32_t dd = DDkey;
6446 int32_t dl = DLkey;
6447 int32_t dr = DRkey;
6448 int32_t mod1a = cheat_modifier_keys[0];
6449 int32_t mod1b = cheat_modifier_keys[1];
6450 int32_t mod2a = cheat_modifier_keys[2];
6451 int32_t mod2b = cheat_modifier_keys[3];
6452 bool done=false;
6453 int32_t ret;
6454
6455 keyboard_control_dlg[0].dp2=get_zc_font(font_lfont);
6456
6457 large_dialog(keyboard_control_dlg);
6458
6459 while(!done)
6460 {
6461 ret = do_zqdialog(keyboard_control_dlg,3);
6462
6463 if(ret==3) // OK
6464 {
6465 int32_t ukeys[num_ukey];
6466 load_ukeys(ukeys);
6467 std::vector<std::string> uniqueError;
6468 for(int32_t q = 0; q < num_ukey; ++q)
6469 {
6470 for(int32_t p = q+1; p < num_ukey; ++p)
6471 {
6472 if(ukeys[q] == ukeys[p] && ukeys[q] != 0)
6473 {
6474 char buf[64];
6475 sprintf(buf, "'%s' conflicts with '%s'", get_ukey_name(q).c_str(), get_ukey_name(p).c_str());
6476 std::string str(buf);
6477 uniqueError.push_back(str);
6478 }
6479 }
6480 }
6481 if(uniqueError.size() == 0)
6482 {
6483 done = true;
6484 save_control_configs(true);
6485 }
6486 else
6487 {
6488 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, keyboard_control_dlg[0].w,keyboard_control_dlg[0].h, 2);
6489 box_out("Cannot have duplicate keybinds!"); box_eol();
6490 for(std::vector<std::string>::iterator it = uniqueError.begin();
6491 it != uniqueError.end(); ++it)
6492 {
6493 box_out((*it).c_str()); box_eol();
6494 }
6495 box_end(true);
6496 }
6497 }
6498 else // Cancel
6499 {
6500 Akey = a;
6501 Bkey = b;
6502 Skey = s;
6503 Lkey = l;
6504 Rkey = r;
6505 Pkey = p;
6506 Exkey1 = ex1;
6507 Exkey2 = ex2;
6508 Exkey3 = ex3;
6509 Exkey4 = ex4;
6510 DUkey = du;
6511 DDkey = dd;
6512 DLkey = dl;
6513 DRkey = dr;
6514 cheat_modifier_keys[0] = mod1a;
6515 cheat_modifier_keys[1] = mod1b;
6516 cheat_modifier_keys[2] = mod2a;
6517 cheat_modifier_keys[3] = mod2b;
6518
6519 done=true;
6520 }
6521
6522 rest(1);
6523 }
6524
6525 return D_O_K;
6526 }
6527
6528 int32_t onGamepad()
6529 {
6530 if (al_get_num_joysticks() == 0)
6531 {
6532 InfoDialog("ZC", "No gamepads detected.").show();
6533 return D_O_K;
6534 }
6535
6536 int32_t a = Abtn;
6537 int32_t b = Bbtn;
6538 int32_t s = Sbtn;
6539 int32_t l = Lbtn;
6540 int32_t r = Rbtn;
6541 int32_t m = Mbtn;
6542 int32_t p = Pbtn;
6543 int32_t ex1 = Exbtn1;
6544 int32_t ex2 = Exbtn2;
6545 int32_t ex3 = Exbtn3;
6546 int32_t ex4 = Exbtn4;
6547 int32_t up = DUbtn;
6548 int32_t down = DDbtn;
6549 int32_t left = DLbtn;
6550 int32_t right = DRbtn;
6551 int32_t joy = joystick_index;
6552 int32_t stick_1 = js_stick_1_x_stick;
6553 int32_t stick_2 = js_stick_2_x_stick;
6554
6555 gamepad_dlg[0].dp2=get_zc_font(font_lfont);
6556 if(analog_movement)
6557 gamepad_dlg[56].flags|=D_SELECTED;
6558 else
6559 gamepad_dlg[56].flags&=~D_SELECTED;
6560
6561 // TODO: should use controller device GUID or name instead of index, otherwise this value is not
6562 // consistent unless exact same number of joysticks is always connected. Name is problematic b/c
6563 // xinput driver doesn't actually get a name (at least, doesn't for my Xbox controller).
6564 // TODO: should store gamepad control mappings per-controller, otherwise switching joystick
6565 // requires remapping every time.
6566 if (joystick_index >= al_get_num_joysticks())
6567 joystick_index = 0;
6568 gamepad_dlg[61].d2 = joystick_index;
6569
6570 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6571 if (!gamepad_dlg_cur_joystick)
6572 {
6573 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6574 return D_CLOSE;
6575 }
6576
6577 large_dialog(gamepad_dlg);
6578
6579 int32_t ret = do_zqdialog(gamepad_dlg,4);
6580
6581 if(ret == 4) //OK
6582 {
6583 analog_movement = gamepad_dlg[56].flags&D_SELECTED;
6584 joystick_index = gamepad_dlg[61].d2;
6585 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6586 if (!gamepad_dlg_cur_joystick)
6587 {
6588 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6589 return D_CLOSE;
6590 }
6591 js_stick_1_y_stick = js_stick_1_x_stick;
6592 js_stick_2_y_stick = js_stick_2_x_stick;
6593 save_control_configs(false);
6594 }
6595 else //Cancel
6596 {
6597 Abtn = a;
6598 Bbtn = b;
6599 Sbtn = s;
6600 Lbtn = l;
6601 Rbtn = r;
6602 Mbtn = m;
6603 Pbtn = p;
6604 Exbtn1 = ex1;
6605 Exbtn2 = ex2;
6606 Exbtn3 = ex3;
6607 Exbtn4 = ex4;
6608 DUbtn = up;
6609 DDbtn = down;
6610 DLbtn = left;
6611 DRbtn = right;
6612 joystick_index = joy;
6613 js_stick_1_x_stick = stick_1;
6614 js_stick_2_x_stick = stick_2;
6615 }
6616
6617 return D_O_K;
6618 }
6619
6620 int32_t onCheatKeys()
6621 {
6622 int32_t oldcheats[Cheat::Last][2];
6623 memcpy(oldcheats, cheatkeys, sizeof(cheatkeys));
6624
6625 bool done=false;
6626
6627 while(!done)
6628 {
6629 bool confirm = false;
6630 CheatKeysDialog(&confirm).show();
6631 if(confirm) // OK
6632 {
6633 std::vector<std::string> uniqueError;
6634 char buf[512];
6635 for(size_t q = 1; q < Cheat::Last; ++q)
6636 {
6637 if(cheatkeys[q][1] && !cheatkeys[q][0])
6638 {
6639 cheatkeys[q][0] = cheatkeys[q][1];
6640 cheatkeys[q][1] = 0;
6641 }
6642 }
6643 for(size_t q = 1; q < Cheat::Last; ++q)
6644 {
6645 if(!bindable_cheat((Cheat)q)) continue;
6646 for(size_t p = q+1; p < Cheat::Last; ++p)
6647 {
6648 if(!bindable_cheat((Cheat)p)) continue;
6649 for(size_t q2 = 0; q2 <= 1; ++q2)
6650 for(size_t p2 = 0; p2 <= 1; ++p2)
6651 {
6652 if(cheatkeys[q][q2] == cheatkeys[p][p2] && cheatkeys[q][q2] != 0)
6653 {
6654 uniqueError.push_back(fmt::format("'{}' ({}) conflicts with '{}' ({}) - both '{}'",
6655 cheat_to_string((Cheat)q), q2?"Alt":"Main",
6656 cheat_to_string((Cheat)p), p2?"Alt":"Main",
6657 get_keystr(cheatkeys[q][q2])));
6658 }
6659 }
6660 }
6661 }
6662 if(uniqueError.size() == 0)
6663 {
6664 done = true;
6665 save_cheatkeys();
6666 }
6667 else
6668 {
6669 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, 500,400, 2);
6670 box_out("Cannot have duplicate keybinds!"); box_eol();
6671 for(std::vector<std::string>::iterator it = uniqueError.begin();
6672 it != uniqueError.end(); ++it)
6673 {
6674 box_out((*it).c_str()); box_eol();
6675 }
6676 box_end(true);
6677 }
6678 }
6679 else // Cancel
6680 {
6681 memcpy(cheatkeys, oldcheats, sizeof(cheatkeys));
6682 done=true;
6683 }
6684 rest(1);
6685 }
6686
6687 return D_O_K;
6688 }
6689
6690 int32_t onSound()
6691 {
6692 if (get_qr(qr_OLD_SCRIPT_VOLUME))
6693 {
6694 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
6695 {
6696 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
6697 }
6698 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
6699 {
6700 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
6701 }
6702 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
6703 {
6704 emusic_volume = (int32_t)FFCore.usr_music_volume;
6705 }
6706 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
6707 {
6708 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
6709 }
6710 }
6711 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
6712 {
6713 pan_style = (int32_t)FFCore.usr_panstyle;
6714 }
6715
6716 int32_t m = midi_volume;
6717 int32_t e = emusic_volume;
6718 int32_t s = sfx_volume;
6719 int32_t p = pan_style;
6720 pan_style = vbound(pan_style,0,3);
6721
6722 sound_dlg[0].dp2=get_zc_font(font_lfont);
6723
6724 large_dialog(sound_dlg);
6725
6726 midi_dp[1] = sound_dlg[6].x;
6727 midi_dp[2] = sound_dlg[6].y;
6728 emus_dp[1] = sound_dlg[8].x;
6729 emus_dp[2] = sound_dlg[8].y;
6730 sfx_dp[1] = sound_dlg[10].x;
6731 sfx_dp[2] = sound_dlg[10].y;
6732 pan_dp[1] = sound_dlg[11].x;
6733 pan_dp[2] = sound_dlg[11].y;
6734 sound_dlg[15].d2 = (midi_volume==255) ? 32 : midi_volume>>3;
6735 sound_dlg[17].d2 = (emusic_volume==255) ? 32 : emusic_volume>>3;
6736 sound_dlg[19].d2 = (sfx_volume==255) ? 32 : sfx_volume>>3;
6737 sound_dlg[20].d2 = pan_style;
6738
6739 int32_t ret = do_zqdialog(sound_dlg,1);
6740
6741 if(ret==2)
6742 {
6743 master_volume(digi_volume,midi_volume);
6744 if (zcmusic)
6745 zcmusic_set_volume(zcmusic, emusic_volume);
6746
6747 int32_t temp_volume = sfx_volume;
6748 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
6749 temp_volume = (sfx_volume * FFCore.usr_sfx_volume) / 10000 / 100;
6750 for(int32_t i=0; i<WAV_COUNT; ++i)
6751 {
6752 if(sfx_voice[i] >= 0)
6753 voice_set_volume(sfx_voice[i], temp_volume);
6754 }
6755 zc_set_config(sfx_sect,"midi",midi_volume);
6756 zc_set_config(sfx_sect,"sfx",sfx_volume);
6757 zc_set_config(sfx_sect,"emusic",emusic_volume);
6758 zc_set_config(sfx_sect,"pan",pan_style);
6759 }
6760 else
6761 {
6762 midi_volume = m;
6763 emusic_volume = e;
6764 sfx_volume = s;
6765 pan_style = p;
6766 }
6767
6768 return D_O_K;
6769 }
6770
6771 int32_t queding(char const* s1, char const* s2, char const* s3)
6772 {
6773 return jwin_alert("ZQuest Classic",s1,s2,s3,"&Yes","&No",'y','n',get_zc_font(font_lfont));
6774 }
6775
6776 int32_t onQuit()
6777 {
6778 if(Playing)
6779 {
6780 int32_t ret=0;
6781
6782 if(get_qr(qr_NOCONTINUE))
6783 {
6784 if(standalone_mode)
6785 {
6786 ret=queding("End current game?",
6787 "The continue screen is disabled; the game",
6788 "will be reloaded from the last save.");
6789 }
6790 else
6791 {
6792 ret=queding("End current game?",
6793 "The continue screen is disabled. You will",
6794 "be returned to the file select screen.");
6795 }
6796 }
6797 else
6798 ret=queding("End current game?",NULL,NULL);
6799
6800 if(ret==1)
6801 {
6802 disableClickToFreeze=false;
6803 Quit=qQUIT;
6804
6805 // Trying to evade a door repair charge?
6806 if(repaircharge)
6807 {
6808 game->change_drupy(-repaircharge);
6809 repaircharge=0;
6810 }
6811
6812 return D_CLOSE;
6813 }
6814 }
6815
6816 return D_O_K;
6817 }
6818
6819 int32_t onTryQuitMenu()
6820 {
6821 return onTryQuit(true);
6822 }
6823
6824 int32_t onTryQuit(bool inMenu)
6825 {
6826 if(Playing && !(GameFlags & GAMEFLAG_NO_F6))
6827 {
6828 if(active_cutscene.can_f6())
6829 {
6830 if(get_qr(qr_OLD_F6))
6831 {
6832 if(inMenu) onQuit();
6833 else /*if(!get_qr(qr_NOCONTINUE))*/ f_Quit(qQUIT);
6834 }
6835 else
6836 {
6837 disableClickToFreeze=false;
6838 GameFlags |= GAMEFLAG_TRYQUIT;
6839 }
6840 return D_CLOSE;
6841 }
6842 else active_cutscene.error();
6843 }
6844
6845 return D_O_K;
6846 }
6847
6848 int32_t onReset()
6849 {
6850 if(queding(" Reset system? ",NULL,NULL)==1)
6851 {
6852 disableClickToFreeze=false;
6853 Quit=qRESET;
6854 replay_quit();
6855 return D_CLOSE;
6856 }
6857
6858 return D_O_K;
6859 }
6860
6861 int32_t onExit()
6862 {
6863 if(queding(" Quit ZQuest Classic? ",NULL,NULL)==1)
6864 {
6865 Quit=qEXIT;
6866 return D_CLOSE;
6867 }
6868
6869 return D_O_K;
6870 }
6871
6872 int32_t onDebug()
6873 {
6874 if(debug_enabled)
6875 set_debug(!get_debug());
6876 return D_O_K;
6877 }
6878
6879 int32_t onHeartBeep()
6880 {
6881 heart_beep=!heart_beep;
6882 zc_set_config(cfg_sect,"heart_beep",heart_beep);
6883 return D_O_K;
6884 }
6885
6886 int32_t onSaveIndicator()
6887 {
6888 use_save_indicator = use_save_indicator ? 0 : 1;
6889 zc_set_config(cfg_sect,"save_indicator",use_save_indicator);
6890 return D_O_K;
6891 }
6892
6893 int32_t onEpilepsy()
6894 {
6895 if(jwin_alert3(
6896 "Epilepsy Flash Reduction",
6897 "Enabling this will reduce the intensity of flashing and screen wave effects.",
6898 "Disabling this will restore standard flash and wavy behaviour.",
6899 "Proceed?",
6900 "&Yes",
6901 "&No",
6902 NULL,
6903 'y',
6904 'n',
6905 0,
6906 get_zc_font(font_lfont)) == 1)
6907 {
6908 epilepsyFlashReduction = epilepsyFlashReduction ? 0 : 1;
6909 zc_set_config(cfg_sect,"epilepsy_flash_reduction",epilepsyFlashReduction);
6910 }
6911 return D_O_K;
6912 }
6913
6914 bool rc = false;
6915
6916 static DIALOG getnum_dlg[] =
6917 {
6918 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
6919 { jwin_win_proc, 80, 80, 160, 72, vc(0), vc(11), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
6920 { jwin_text_proc, 104, 104+4, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
6921 { jwin_edit_proc, 168, 104, 48, 16, 0, 0, 0, 0, 6, 0, NULL, NULL, NULL },
6922 { jwin_button_proc, 90, 126, 61, 21, vc(0), vc(11), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6923 { jwin_button_proc, 170, 126, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6924 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6925 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6926 };
6927
6928 int32_t getnumber(const char *prompt,int32_t initialval)
6929 {
6930 char buf[20];
6931 sprintf(buf,"%d",initialval);
6932 getnum_dlg[0].dp=(void *)prompt;
6933 getnum_dlg[0].dp2=get_zc_font(font_lfont);
6934 getnum_dlg[2].dp=buf;
6935
6936 large_dialog(getnum_dlg);
6937
6938 if(do_zqdialog(getnum_dlg,2)==3)
6939 return atoi(buf);
6940
6941 return initialval;
6942 }
6943
6944 int32_t onLife()
6945 {
6946 int value = vbound(getnumber("Life",game->get_life()),1,game->get_maxlife());
6947 cheats_enqueue(Cheat::Life, value);
6948 return D_O_K;
6949 }
6950
6951 int32_t onHeartC()
6952 {
6953 int max_life = vbound(getnumber("Heart Containers",game->get_maxlife()/game->get_hp_per_heart()),1,4095) * game->get_hp_per_heart();
6954 int life = vbound(getnumber("Life",game->get_life()/game->get_hp_per_heart()),1,max_life/game->get_hp_per_heart())*game->get_hp_per_heart();
6955 cheats_enqueue(Cheat::MaxLife, max_life);
6956 cheats_enqueue(Cheat::Life, life);
6957 return D_O_K;
6958 }
6959
6960 int32_t onMagicC()
6961 {
6962 int max_magic = vbound(getnumber("Magic Containers",game->get_maxmagic()/game->get_mp_per_block()),0,2047) * game->get_mp_per_block();
6963 int magic = vbound(getnumber("Magic",game->get_magic()/game->get_mp_per_block()),0,max_magic/game->get_mp_per_block())*game->get_mp_per_block();
6964 cheats_enqueue(Cheat::MaxMagic, max_magic);
6965 cheats_enqueue(Cheat::Magic, magic);
6966 return D_O_K;
6967 }
6968
6969 int32_t onRupies()
6970 {
6971 int value = vbound(getnumber("Rupees",game->get_rupies()),0,game->get_maxcounter(1));
6972 cheats_enqueue(Cheat::Rupies, value);
6973 return D_O_K;
6974 }
6975
6976 int32_t onMaxBombs()
6977 {
6978 int value = vbound(getnumber("Max Bombs",game->get_maxbombs()),0,0xFFFF);
6979 cheats_enqueue(Cheat::MaxBombs, value);
6980 cheats_enqueue(Cheat::Bombs, value);
6981 return D_O_K;
6982 }
6983
6984 int32_t onRefillLife()
6985 {
6986 cheats_enqueue(Cheat::Life, game->get_maxlife());
6987 return D_O_K;
6988 }
6989 int32_t onRefillMagic()
6990 {
6991 cheats_enqueue(Cheat::Magic, game->get_maxmagic());
6992 return D_O_K;
6993 }
6994 int32_t onClock()
6995 {
6996 cheats_enqueue(Cheat::Clock);
6997 return D_O_K;
6998 }
6999
7000 int32_t onQstPath()
7001 {
7002 char initial_path[2048];
7003 chop_path(qstdir);
7004 strcpy(initial_path, qstdir);
7005
7006 if (auto result = prompt_for_existing_folder("Quest File Directory", initial_path, "qst"))
7007 {
7008 char* path = result->data();
7009 chop_path(path);
7010 fix_filename_case(path);
7011 fix_filename_slashes(path);
7012 strcpy(qstdir,path);
7013 strcpy(qstpath,qstdir);
7014 zc_set_config("zeldadx","quest_dir",qstdir);
7015 flush_config_file();
7016 }
7017
7018 return D_O_K;
7019 }
7020
7021 #include "dialog/cheat_dialog.h"
7022 int32_t onCheat()
7023 {
7024 call_setcheat_dialog();
7025 game->set_cheat(maxcheat);
7026 if(cheat) game->did_cheat(true);
7027 return D_O_K;
7028 }
7029
7030 int32_t onCheatRupies()
7031 {
7032 cheats_enqueue(Cheat::Rupies, game->get_maxcounter(1));
7033 return D_O_K;
7034 }
7035
7036 int32_t onCheatArrows()
7037 {
7038 cheats_enqueue(Cheat::Arrows, game->get_maxarrows());
7039 return D_O_K;
7040 }
7041
7042 int32_t onCheatBombs()
7043 {
7044 cheats_enqueue(Cheat::Bombs, game->get_maxbombs(), game->get_maxcounter(6));
7045 return D_O_K;
7046 }
7047
7048 // *** screen saver
7049
7050 19209276 int32_t after_time()
7051 {
7052
1/2
✓ Branch 0 taken 19209276 times.
✗ Branch 1 not taken.
19209276 if(ss_enable == 0)
7053 return INT_MAX;
7054
7055
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19209276 times.
19209276 if(ss_after <= 0)
7056 return 5 * 60;
7057
7058
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19209276 times.
19209276 if(ss_after <= 3)
7059 return ss_after * 15 * 60;
7060
7061
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19209276 times.
19209276 if(ss_after <= 13)
7062 return (ss_after - 3) * 60 * 60;
7063
7064 19209276 return MAX_IDLE + 1;
7065 19209276 }
7066
7067 static const char *after_str[15] =
7068 {
7069 " 5 sec", "15 sec", "30 sec", "45 sec", " 1 min", " 2 min", " 3 min",
7070 " 4 min", " 5 min", " 6 min", " 7 min", " 8 min", " 9 min", "10 min",
7071 "Never"
7072 };
7073
7074 const char *after_list(int32_t index, int32_t *list_size)
7075 {
7076 if(index < 0)
7077 {
7078 *list_size = 15;
7079 return NULL;
7080 }
7081
7082 return after_str[index];
7083 }
7084
7085 429 static ListData after__list(after_list, &font);
7086
7087 static DIALOG scrsaver_dlg[] =
7088 {
7089 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
7090 429 { jwin_win_proc, 32, 64, 256, 136, 0, 0, 0, D_EXIT, 0, 0, (void *) "Screen Saver Settings", NULL, NULL },
7091 429 { jwin_frame_proc, 42, 92, 236, 70, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
7092 429 { jwin_text_proc, 60, 104, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Run After", NULL, NULL },
7093 429 { jwin_text_proc, 60, 128, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Speed", NULL, NULL },
7094 429 { jwin_text_proc, 60, 144, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Density", NULL, NULL },
7095 429 { jwin_droplist_proc, 144, 100, 96, 16, 0, 0, 0, 0, 0, 0, (void *) &after__list, NULL, NULL },
7096 429 { jwin_slider_proc, 144, 128, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7097 429 { jwin_slider_proc, 144, 144, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7098 429 { jwin_button_proc, 42, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
7099 429 { jwin_button_proc, 124, 170, 72, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Preview", NULL, NULL },
7100 429 { jwin_button_proc, 218, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
7101 429 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7102 429 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
7103 };
7104
7105 int32_t onScreenSaver()
7106 {
7107 scrsaver_dlg[0].dp2=get_zc_font(font_lfont);
7108 int32_t oldcfgs[3];
7109 scrsaver_dlg[5].d1 = scrsaver_dlg[5].d2 = oldcfgs[0] = ss_after;
7110 scrsaver_dlg[6].d2 = oldcfgs[1] = ss_speed;
7111 scrsaver_dlg[7].d2 = oldcfgs[2] = ss_density;
7112
7113 large_dialog(scrsaver_dlg);
7114
7115 int32_t ret = do_zqdialog(scrsaver_dlg,-1);
7116
7117 if(ret == 8 || ret == 9)
7118 {
7119 ss_after = scrsaver_dlg[5].d1;
7120 ss_speed = scrsaver_dlg[6].d2;
7121 ss_density = scrsaver_dlg[7].d2;
7122 if(oldcfgs[0] != ss_after)
7123 zc_set_config(cfg_sect,"ss_after",ss_after);
7124 if(oldcfgs[1] != ss_speed)
7125 zc_set_config(cfg_sect,"ss_speed",ss_speed);
7126 if(oldcfgs[2] != ss_density)
7127 zc_set_config(cfg_sect,"ss_density",ss_density);
7128 }
7129
7130 if(ret == 9)
7131 // preview Screen Saver
7132 {
7133 clear_keybuf();
7134 Matrix(ss_speed, ss_density, 30);
7135 system_pal(true);
7136 sys_mouse();
7137 }
7138
7139 return D_O_K;
7140 }
7141
7142 /***** Menus *****/
7143
7144 enum
7145 {
7146 MENUID_GAME_LOADQUEST,
7147 MENUID_GAME_ENDGAME,
7148 };
7149
1/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
429 static NewMenu game_menu
7150 3432 {
7151
3/6
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 429 times.
✗ Branch 5 not taken.
429 { "&Continue","ESC", onContinue },
7152
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 {},
7153
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "L&oad Quest...", onCustomGame, MENUID_GAME_LOADQUEST },
7154
3/6
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 429 times.
✗ Branch 5 not taken.
429 { "&End Game","F6", onTryQuitMenu, MENUID_GAME_ENDGAME },
7155
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 {},
7156 #ifdef __EMSCRIPTEN__
7157 { "&Reset","F7", onReset },
7158 #elif defined(ALLEGRO_MACOSX)
7159 { "&Reset","F7", onReset },
7160 { "&Quit","F8", onExit },
7161 #else
7162
3/6
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 429 times.
✗ Branch 5 not taken.
429 { "&Reset","F9", onReset },
7163
3/6
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 429 times.
✗ Branch 5 not taken.
429 { "&Quit","F10", onExit },
7164 #endif
7165 };
7166
7167
1/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
429 static NewMenu snapshot_format_menu
7168 3003 {
7169
4/8
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 429 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 429 times.
✗ Branch 7 not taken.
429 { "&BMP", std::bind(onSetSnapshotFormat, ssfmtBMP) },
7170
4/8
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 429 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 429 times.
✗ Branch 7 not taken.
429 { "&GIF", std::bind(onSetSnapshotFormat, ssfmtGIF) },
7171
4/8
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 429 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 429 times.
✗ Branch 7 not taken.
429 { "&JPG", std::bind(onSetSnapshotFormat, ssfmtJPG) },
7172
4/8
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 429 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 429 times.
✗ Branch 7 not taken.
429 { "&PNG", std::bind(onSetSnapshotFormat, ssfmtPNG) },
7173
4/8
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 429 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 429 times.
✗ Branch 7 not taken.
429 { "PC&X", std::bind(onSetSnapshotFormat, ssfmtPCX) },
7174
4/8
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 429 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 429 times.
✗ Branch 7 not taken.
429 { "&TGA", std::bind(onSetSnapshotFormat, ssfmtTGA) },
7175 };
7176
7177
1/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
429 static NewMenu bottom_8_pixels_menu
7178 1716 {
7179
4/8
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 429 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 429 times.
✗ Branch 7 not taken.
429 { "&Default (qst)", std::bind(onSetBottom8Pixels, 0) },
7180
4/8
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 429 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 429 times.
✗ Branch 7 not taken.
429 { "&On", std::bind(onSetBottom8Pixels, 1) },
7181
4/8
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 429 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 429 times.
✗ Branch 7 not taken.
429 { "&Off", std::bind(onSetBottom8Pixels, 2) },
7182 };
7183
7184
1/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
429 static NewMenu controls_menu
7185 1716 {
7186
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Key&board...", onKeyboard },
7187
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Gamepad...", onGamepad },
7188
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Cheat Keys...", onCheatKeys },
7189 };
7190
7191
1/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
429 static NewMenu name_entry_mode_menu
7192 1716 {
7193
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Keyboard", onKeyboardEntry },
7194
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Letter Grid", onLetterGridEntry },
7195
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Extended Letter Grid", onExtLetterGridEntry },
7196 };
7197
7198 static void set_controls_menu_active()
7199 {
7200
7201 }
7202
7203 enum
7204 {
7205 MENUID_WINDOW_LOCK_ASPECT,
7206 MENUID_WINDOW_LOCK_INTSCALE,
7207 MENUID_WINDOW_SAVE_SIZE,
7208 MENUID_WINDOW_SAVE_POS,
7209 MENUID_WINDOW_STRETCH,
7210 };
7211
1/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
429 static NewMenu window_menu
7212 2574 {
7213
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Lock Aspect Ratio", onDragAspect, MENUID_WINDOW_LOCK_ASPECT },
7214
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Lock Integer Scale", onIntegerScaling, MENUID_WINDOW_LOCK_INTSCALE },
7215
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Save Size Changes", onSaveDragResize, MENUID_WINDOW_SAVE_SIZE },
7216
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Save Position Changes", onWinPosSave, MENUID_WINDOW_SAVE_POS },
7217
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Stretch Game Area", onStretchGame, MENUID_WINDOW_STRETCH },
7218 };
7219 void call_zc_options_dlg();
7220 enum
7221 {
7222 MENUID_OPTIONS_PAUSE_BG,
7223 MENUID_OPTIONS_EPILEPSYPROT,
7224 MENUID_OPTIONS_SHOWBOTTOMPIXELS,
7225 };
7226
1/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
429 static NewMenu options_menu
7227 3432 {
7228
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Name &Entry Mode", &name_entry_mode_menu },
7229
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "S&napshot Format", &snapshot_format_menu },
7230
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Window Settings", &window_menu },
7231
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Epilepsy Flash Reduction", onEpilepsy, MENUID_OPTIONS_EPILEPSYPROT },
7232
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Pause In Background", onPauseInBackground, MENUID_OPTIONS_PAUSE_BG },
7233
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Show Bottom 8 Pixels", &bottom_8_pixels_menu, MENUID_OPTIONS_SHOWBOTTOMPIXELS },
7234
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "More Options", call_zc_options_dlg },
7235 };
7236 enum
7237 {
7238 MENUID_SETTINGS_CONTROLS,
7239 MENUID_SETTINGS_CAPFPS,
7240 MENUID_SETTINGS_SHOWFPS,
7241 MENUID_SETTINGS_SHOWTIME,
7242 MENUID_SETTINGS_CLICK_FREEZE,
7243 MENUID_SETTINGS_TRANSLAYERS,
7244 MENUID_SETTINGS_NESQUIT,
7245 MENUID_SETTINGS_VOLKEYS,
7246 MENUID_SETTINGS_HEARTBEEP,
7247 MENUID_SETTINGS_SAVEINDICATOR,
7248 MENUID_SETTINGS_DEBUG,
7249 };
7250
1/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
429 static NewMenu settings_menu
7251 7293 {
7252
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Sound...", onSound },
7253
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "C&ontrols", &controls_menu, MENUID_SETTINGS_CONTROLS },
7254
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 {},
7255
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Options", &options_menu },
7256
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 {},
7257
3/6
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 429 times.
✗ Branch 5 not taken.
429 { "&Cap FPS","F1", onThrottleFPS, MENUID_SETTINGS_CAPFPS },
7258
3/6
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 429 times.
✗ Branch 5 not taken.
429 { "Show &FPS","F2", onShowFPS, MENUID_SETTINGS_SHOWFPS },
7259
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Show &Time", onShowTime, MENUID_SETTINGS_SHOWTIME },
7260
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Click to Freeze", onClickToFreeze, MENUID_SETTINGS_CLICK_FREEZE },
7261
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Cont. &Heart Beep", onHeartBeep, MENUID_SETTINGS_HEARTBEEP },
7262
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Show Trans. &Layers", onTransLayers, MENUID_SETTINGS_TRANSLAYERS },
7263
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Up+A+B To &Quit", onNESquit, MENUID_SETTINGS_NESQUIT },
7264
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Volume &Keys", onVolKeys, MENUID_SETTINGS_VOLKEYS },
7265
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Sa&ve Indicator", onSaveIndicator, MENUID_SETTINGS_SAVEINDICATOR },
7266
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 {},
7267
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Debu&g", onDebug, MENUID_SETTINGS_DEBUG },
7268 };
7269
7270 enum
7271 {
7272 MENUID_MISC_FULLSCREEN,
7273 MENUID_MISC_VIDMODE,
7274 MENUID_MISC_QUEST_INFO,
7275 MENUID_MISC_QUEST_DIR,
7276 MENUID_MISC_CONSOLE,
7277 MENUID_MISC_CLEAR_CONSOLE_ON_LOAD,
7278 };
7279
1/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
429 static NewMenu misc_menu
7280 6435 {
7281
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&About...", onAbout },
7282 // TODO: re-enable, but: 1) do not use a bitmap thing that is hard to update 2) update names and 3) don't use the Z-word.
7283 // { "&Credits...", onCredits },
7284
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Fullscreen", onFullscreenMenu, MENUID_MISC_FULLSCREEN },
7285
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Video Mode...", onVidMode, MENUID_MISC_VIDMODE },
7286
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 {},
7287
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Quest Info...", onQuest, MENUID_MISC_QUEST_INFO },
7288
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Quest &MIDI Info...", onMIDICredits },
7289
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Quest &Directory...", onQstPath, MENUID_MISC_QUEST_DIR },
7290
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 {},
7291
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Take &Snapshot F12", onSnapshot },
7292
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Sc&reen Saver...", onScreenSaver },
7293
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Save ZC Configuration", OnSaveZCConfig },
7294
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Show Console", onConsole, MENUID_MISC_CONSOLE },
7295
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Clear Console on Qst Load", onClrConsoleOnLoad, MENUID_MISC_CLEAR_CONSOLE_ON_LOAD },
7296
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Clear Directory Cache", OnnClearQuestDir },
7297 };
7298
7299 enum
7300 {
7301 MENUID_REFILL_ARROWS,
7302 };
7303
1/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
429 static NewMenu refill_menu
7304 2574 {
7305
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Life", onRefillLife },
7306
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Magic", onRefillMagic },
7307
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Bombs", onCheatBombs },
7308
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Rupees", onCheatRupies },
7309
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Arrows", onCheatArrows, MENUID_REFILL_ARROWS },
7310 };
7311
7312 enum
7313 {
7314 MENUID_SHOW_L0,
7315 MENUID_SHOW_L1,
7316 MENUID_SHOW_L2,
7317 MENUID_SHOW_L3,
7318 MENUID_SHOW_L4,
7319 MENUID_SHOW_L5,
7320 MENUID_SHOW_L6,
7321 MENUID_SHOW_OVER,
7322 MENUID_SHOW_PUSH,
7323 MENUID_SHOW_FFC,
7324 MENUID_SHOW_SPR,
7325 MENUID_SHOW_SCRIPTNAME,
7326 MENUID_SHOW_SOLIDITY,
7327 MENUID_SHOW_HITBOX,
7328 MENUID_SHOW_EFFECT,
7329 };
7330
1/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
429 static NewMenu show_menu
7331 8151 {
7332
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Combos", onShowLayer0, MENUID_SHOW_L0 },
7333
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Layer 1", onShowLayer1, MENUID_SHOW_L1 },
7334
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Layer 2", onShowLayer2, MENUID_SHOW_L2 },
7335
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Layer 3", onShowLayer3, MENUID_SHOW_L3 },
7336
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Layer 4", onShowLayer4, MENUID_SHOW_L4 },
7337
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Layer 5", onShowLayer5, MENUID_SHOW_L5 },
7338
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Layer 6", onShowLayer6, MENUID_SHOW_L6 },
7339
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Overhead Combos", onShowLayerO, MENUID_SHOW_OVER },
7340
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Push Blocks", onShowLayerP, MENUID_SHOW_PUSH },
7341
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Freeform Combos", onShowLayerF, MENUID_SHOW_FFC },
7342
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Sprites", onShowLayerS, MENUID_SHOW_SPR },
7343
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 {},
7344
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Current FFC Scripts", onShowFFScripts, MENUID_SHOW_SCRIPTNAME },
7345
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 {},
7346
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Walkability", onShowLayerW, MENUID_SHOW_SOLIDITY },
7347
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Hitboxes", onShowHitboxes, MENUID_SHOW_HITBOX },
7348
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Effects", onShowLayerE, MENUID_SHOW_EFFECT },
7349
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Info Opacity", onShowInfoOpacity },
7350 };
7351
7352 enum
7353 {
7354 MENUID_CHEAT_CHOP_L1,
7355 MENUID_CHEAT_CHOP_L2,
7356 MENUID_CHEAT_CHOP_L3,
7357 MENUID_CHEAT_CHOP_L4,
7358 MENUID_CHEAT_INVULN,
7359 MENUID_CHEAT_NOCLIP,
7360 MENUID_CHEAT_IGNORESV,
7361 MENUID_CHEAT_GOFAST,
7362 };
7363
1/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
429 static NewMenu cheat_menu
7364 7293 {
7365
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Set &Cheat", onCheat },
7366
1/2
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
429 { MENUID_CHEAT_CHOP_L1 },
7367
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Re&fill", &refill_menu },
7368
1/2
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
429 { MENUID_CHEAT_CHOP_L2 },
7369
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Invincible", onClock, MENUID_CHEAT_INVULN },
7370
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Ma&x Bombs...", onMaxBombs },
7371
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Heart Containers...", onHeartC },
7372
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Magic Containers...", onMagicC },
7373
1/2
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
429 { MENUID_CHEAT_CHOP_L3 },
7374
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Hero Data...", onCheatConsole },
7375
1/2
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
429 { MENUID_CHEAT_CHOP_L4 },
7376
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Walk Through &Walls", onNoWalls, MENUID_CHEAT_NOCLIP },
7377
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Hero Ignores Side&view", onIgnoreSideview, MENUID_CHEAT_IGNORESV },
7378
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Quick Movement", onGoFast, MENUID_CHEAT_GOFAST },
7379
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Kill All Enemies", onKillCheat },
7380
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Trigger &Secrets", onSecretsCheat },
7381
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Trigger Secrets Perm", onSecretsCheatPerm },
7382
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Show/Hide Layer", &show_menu },
7383
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "Toggle &Light", onLightSwitch },
7384
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Goto Location...", onGoTo },
7385 };
7386
7387 #if DEVLEVEL > 0
7388 int32_t devLogging();
7389 int32_t devDebug();
7390 int32_t devTimestmp();
7391 #if DEVLEVEL > 1
7392 int32_t setCheat();
7393 #endif //DEVLEVEL > 1
7394 enum
7395 {
7396 MENUID_DEV_LOGGING,
7397 MENUID_DEV_DEBUG,
7398 MENUID_DEV_TIMESTAMP,
7399 MENUID_DEV_SETCHEAT,
7400 };
7401 static NewMenu dev_menu
7402 {
7403 { "&Force Error Log", devLogging, MENUID_DEV_LOGGING },
7404 // { "&Extra Debug Log", devDebug, MENUID_DEV_DEBUG },
7405 { "&Timestamp Log", devTimestmp, MENUID_DEV_TIMESTAMP },
7406 #if DEVLEVEL > 1
7407 {},
7408 { "Set &Cheat", setCheat, MENUID_DEV_SETCHEAT },
7409 #endif //DEVLEVEL > 1
7410 };
7411 int32_t devLogging()
7412 {
7413 dev_logging = !dev_logging;
7414 dev_menu.select_uid(MENUID_DEV_LOGGING, dev_logging);
7415 return D_O_K;
7416 }
7417 // int32_t devDebug()
7418 // {
7419 // dev_debug = !dev_debug;
7420 // dev_menu.select_uid(MENUID_DEV_DEBUG, dev_debug);
7421 // dev_menu[dv_dbg].flags = dev_debug ? D_SELECTED : 0;
7422 // return D_O_K;
7423 // }
7424 int32_t devTimestmp()
7425 {
7426 dev_timestmp = !dev_timestmp;
7427 dev_menu.select_uid(MENUID_DEV_TIMESTAMP, dev_timestmp);
7428 return D_O_K;
7429 }
7430 #if DEVLEVEL > 1
7431 int32_t setCheat()
7432 {
7433 cheat = (vbound(getnumber("Cheat Level",cheat), 0, 4));
7434 return D_O_K;
7435 }
7436 #endif //DEVLEVEL > 1
7437 #endif //DEVLEVEL > 0
7438
7439 enum
7440 {
7441 MENUID_PLAYER_CHEAT,
7442 };
7443
1/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
429 TopMenu the_player_menu
7444 2574 {
7445
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Game", &game_menu },
7446
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Settings", &settings_menu },
7447
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Cheat", &cheat_menu, MENUID_PLAYER_CHEAT, true },
7448
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&Replay", &replay_menu },
7449
2/4
✓ Branch 0 taken 429 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 429 times.
✗ Branch 3 not taken.
429 { "&ZC", &misc_menu },
7450 #if DEVLEVEL > 0
7451 { "&Dev", &dev_menu },
7452 #endif
7453 };
7454
7455 int32_t onPauseInBackground()
7456 {
7457 if(jwin_alert3(
7458 "Toggle Pause In Background",
7459 "This action will change whether ZC Player pauses when the window loses focus.",
7460 "",
7461 "Proceed?",
7462 "&Yes",
7463 "&No",
7464 NULL,
7465 'y',
7466 'n',
7467 0,
7468 get_zc_font(font_lfont)) == 1)
7469 {
7470 pause_in_background = pause_in_background ? 0 : 1;
7471 zc_set_config("zeldadx","pause_in_background", pause_in_background);
7472 int switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7473 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7474 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7475 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7476 }
7477 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7478 return D_O_K;
7479 }
7480
7481 int32_t onKeyboardEntry()
7482 {
7483 NameEntryMode=0;
7484 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7485 return D_O_K;
7486 }
7487
7488 int32_t onLetterGridEntry()
7489 {
7490 NameEntryMode=1;
7491 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7492 return D_O_K;
7493 }
7494
7495 int32_t onExtLetterGridEntry()
7496 {
7497 NameEntryMode=2;
7498 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7499 return D_O_K;
7500 }
7501
7502 static BITMAP* oldscreen;
7503 int32_t onFullscreenMenu()
7504 {
7505 PALETTE oldpal;
7506 get_palette(oldpal);
7507
7508 fullscreen = !fullscreen;
7509 all_toggle_fullscreen(fullscreen);
7510 zc_set_config("zeldadx","fullscreen",fullscreen);
7511
7512 zc_set_palette(oldpal);
7513 gui_mouse_focus=0;
7514 extern int32_t switch_type;
7515 switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7516 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7517 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7518 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7519 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7520 misc_menu.select_uid(MENUID_MISC_VIDMODE, isFullScreen());
7521
7522 return D_O_K;
7523 }
7524
7525 325 void fix_menu()
7526 {
7527
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 325 times.
325 if(!debug_enabled)
7528 325 settings_menu.chop_index = 13;
7529 325 }
7530
7531 int32_t onSetSnapshotFormat(SnapshotType format)
7532 {
7533 SnapshotFormat = format;
7534 zc_set_config("zeldadx", "snapshot_format", format);
7535 snapshot_format_menu.select_only_index(format);
7536 return D_O_K;
7537 }
7538
7539 int32_t onSetBottom8Pixels(int option)
7540 {
7541 ShowBottomPixels = option;
7542 zc_set_config("zeldadx", "bottom_8_px", option);
7543 bottom_8_pixels_menu.select_only_index(option);
7544
7545 int qr = qr_HIDE_BOTTOM_8_PIXELS;
7546 bool value = false;
7547 if (option == 0)
7548 value = get_bit(quest_rules, qr) != 0; // This is the original value, as set in the qst file (or via scripting).
7549 else if (option == 1)
7550 value = false;
7551 else if (option == 2)
7552 value = true;
7553 enqueue_qr_change(qr, value);
7554
7555 return D_O_K;
7556 }
7557
7558 3023 void updateShowBottomPixels()
7559 {
7560 // It's too tricky the allow modifying the screen height between opening and closing the
7561 // active subscreen.
7562
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 2997 times.
3023 if (subscreen_open)
7563 26 return;
7564
7565
1/2
✓ Branch 0 taken 2997 times.
✗ Branch 1 not taken.
2997 if (!GameLoaded)
7566 show_bottom_8px = false;
7567 else
7568 2997 show_bottom_8px = !get_qr(qr_HIDE_BOTTOM_8_PIXELS);
7569
7570 2997 int target_bitmap_height = show_bottom_8px ? 232 : 224;
7571
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 117 times.
2997 if (framebuf->h != target_bitmap_height)
7572 {
7573 117 BITMAP* new_framebuf = create_bitmap_ex(8, 256, target_bitmap_height);
7574 117 clear_bitmap(new_framebuf);
7575 117 blit(framebuf, new_framebuf, 0, 0, 0, 0, new_framebuf->w, new_framebuf->h);
7576
7577 117 BITMAP* new_framebuf_active_subscreen = create_bitmap_ex(8, 256, target_bitmap_height);
7578 117 clear_bitmap(new_framebuf_active_subscreen);
7579
1/2
✓ Branch 0 taken 117 times.
✗ Branch 1 not taken.
117 if (framebuf_no_passive_subscreen)
7580 117 blit(framebuf_no_passive_subscreen, new_framebuf_active_subscreen, 0, 0, 0, 0, new_framebuf_active_subscreen->w, new_framebuf_active_subscreen->h);
7581
7582 117 destroy_bitmap(framebuf);
7583 117 destroy_bitmap(framebuf_no_passive_subscreen);
7584 117 destroy_bitmap(script_menu_buf);
7585 117 destroy_bitmap(f6_menu_buf);
7586 117 destroy_bitmap(darkscr_bmp);
7587 117 destroy_bitmap(darkscr_bmp_trans);
7588
7589 117 framebuf = new_framebuf;
7590 117 framebuf_no_passive_subscreen = new_framebuf_active_subscreen;
7591 117 script_menu_buf = create_bitmap_ex(8, 256, target_bitmap_height);
7592 117 f6_menu_buf = create_bitmap_ex(8, 256, target_bitmap_height);
7593 117 darkscr_bmp = create_bitmap_ex(8, 256, target_bitmap_height);
7594 117 darkscr_bmp_trans = create_bitmap_ex(8, 256, target_bitmap_height);
7595
7596 117 rti_game.a4_bitmap = framebuf;
7597 117 rti_game.set_size(framebuf->w, framebuf->h);
7598 117 al_set_new_bitmap_flags(ALLEGRO_CONVERT_BITMAP);
7599 117 al_destroy_bitmap(rti_game.bitmap);
7600 117 rti_game.bitmap = create_a5_bitmap(framebuf->w, framebuf->h);
7601 117 al_destroy_bitmap(rti_infolayer.bitmap);
7602 117 rti_infolayer.bitmap = create_a5_bitmap(framebuf->w, framebuf->h);
7603 117 rti_infolayer.set_size(framebuf->w, framebuf->h);
7604 117 }
7605 3023 }
7606
7607 void color_layer(RGB *src,RGB *dest,char r,char g,char b,char pos,int32_t from,int32_t to)
7608 {
7609 PALETTE tmp;
7610
7611 for(int32_t i=0; i<256; i++)
7612 {
7613 tmp[i].r=r;
7614 tmp[i].g=g;
7615 tmp[i].b=b;
7616 }
7617
7618 fade_interpolate(src,tmp,dest,pos,from,to);
7619 }
7620
7621 59 void system_pal(bool force)
7622 {
7623
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
59 if(is_sys_pal && !force) return;
7624 59 is_sys_pal = true;
7625 59 load_colorset(gui_colorset, syspal, jwin_a5_colors);
7626 59 hw_palette = &syspal;
7627 59 update_hw_pal = true;
7628 59 }
7629
7630 static uint32_t entered_sys_pal = 0;
7631 59 void enter_sys_pal()
7632 {
7633
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
59 if(is_sys_pal)
7634 {
7635 if(entered_sys_pal)
7636 ++entered_sys_pal;
7637 return;
7638 }
7639 59 sys_mouse();
7640 59 system_pal(true);
7641 59 ++entered_sys_pal;
7642 59 }
7643 59 void exit_sys_pal()
7644 {
7645
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
59 if(entered_sys_pal)
7646 {
7647
1/2
✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
59 if(!--entered_sys_pal)
7648 {
7649 59 game_pal();
7650 59 game_mouse();
7651 59 }
7652 59 }
7653 59 }
7654
7655 void switch_out_callback()
7656 {
7657 if (pause_in_background && !MenuOpen)
7658 {
7659 System();
7660 }
7661 }
7662
7663 void switch_in_callback()
7664 {
7665 }
7666
7667 1206 void game_pal()
7668 {
7669 1206 is_sys_pal = false;
7670 1206 entered_sys_pal = 0;
7671 1206 hw_palette = &RAMpal;
7672 1206 update_hw_pal = true;
7673 1206 }
7674
7675 static char bar_str[] = "";
7676
7677 59 void music_pause()
7678 {
7679 //al_pause_duh(tmplayer);
7680 59 zcmusic_pause(zcmusic, ZCM_PAUSE);
7681
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
59 if(zcmixer->oldtrack)
7682 zcmusic_pause(zcmixer->oldtrack, ZCM_PAUSE);
7683 59 zc_midi_pause();
7684 59 }
7685
7686 void music_resume()
7687 {
7688 //al_resume_duh(tmplayer);
7689 zcmusic_pause(zcmusic, ZCM_RESUME);
7690 if (zcmixer->oldtrack)
7691 zcmusic_pause(zcmixer->oldtrack, ZCM_RESUME);
7692 zc_midi_resume();
7693 }
7694
7695 8351 void music_stop()
7696 {
7697 //al_stop_duh(tmplayer);
7698 //unload_duh(tmusic);
7699 //tmusic=NULL;
7700 //tmplayer=NULL;
7701 8351 zcmusic_stop(zcmusic);
7702 8351 zcmusic_unload_file(zcmusic);
7703
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8351 times.
8351 if (zcmixer->oldtrack)
7704 {
7705 zcmusic_stop(zcmixer->oldtrack);
7706 zcmusic_unload_file(zcmixer->oldtrack);
7707 }
7708 8351 zcmixer->newtrack = NULL;
7709 8351 zc_stop_midi();
7710 8351 currmidi=-1;
7711 8351 }
7712
7713 bool reload_fonts = false;
7714 void System()
7715 {
7716 mouse_down = gui_mouse_b();
7717 music_pause();
7718 pause_all_sfx();
7719 MenuOpen = true;
7720 enter_sys_pal();
7721 // FONT *oldfont=font;
7722 // font=tfont;
7723
7724 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7725 misc_menu.disable_uid(MENUID_MISC_VIDMODE, isFullScreen());
7726
7727 #if DEVLEVEL > 1
7728 dev_menu.disable_uid(MENUID_DEV_SETCHEAT, !Playing);
7729 #endif
7730 game_menu.disable_uid(MENUID_GAME_LOADQUEST, get_unset_save_slot());
7731 game_menu.disable_uid(MENUID_GAME_ENDGAME, !Playing);
7732 misc_menu.disable_uid(MENUID_MISC_QUEST_INFO, !Playing);
7733 misc_menu.disable_uid(MENUID_MISC_QUEST_DIR, Playing);
7734 clear_keybuf();
7735
7736 clear_bitmap(menu_bmp);
7737 oldscreen = screen;
7738 screen = menu_bmp;
7739
7740 the_player_menu.reset_state();
7741 the_player_menu.position(0, 0);
7742
7743 bool running = true;
7744 bool esc = key[KEY_ESC] || cMbtn();
7745 bool autopop = esc;
7746 do
7747 {
7748 if(reload_fonts)
7749 {
7750 init_custom_fonts();
7751 clear_bitmap(menu_bmp);
7752 broadcast_dialog_message(MSG_DRAW, 0);
7753 reload_fonts = false;
7754 }
7755 if(handle_close_btn_quit())
7756 break;
7757
7758 //update submenus
7759 {
7760 settings_menu.disable_uid(MENUID_SETTINGS_CONTROLS, replay_is_replaying());
7761 settings_menu.select_uid(MENUID_SETTINGS_CAPFPS, Throttlefps);
7762 settings_menu.select_uid(MENUID_SETTINGS_SHOWFPS, ShowFPS);
7763 settings_menu.select_uid(MENUID_SETTINGS_SHOWTIME, ShowGameTime);
7764 settings_menu.select_uid(MENUID_SETTINGS_CLICK_FREEZE, ClickToFreeze);
7765 settings_menu.select_uid(MENUID_SETTINGS_TRANSLAYERS, TransLayers);
7766 settings_menu.select_uid(MENUID_SETTINGS_NESQUIT, NESquit);
7767 settings_menu.select_uid(MENUID_SETTINGS_VOLKEYS, volkeys);
7768
7769 window_menu.select_uid(MENUID_WINDOW_LOCK_ASPECT, DragAspect);
7770 window_menu.select_uid(MENUID_WINDOW_LOCK_INTSCALE, scaleForceInteger);
7771 window_menu.select_uid(MENUID_WINDOW_SAVE_SIZE, SaveDragResize);
7772 window_menu.select_uid(MENUID_WINDOW_SAVE_POS, SaveWinPos);
7773 window_menu.select_uid(MENUID_WINDOW_STRETCH, stretchGame);
7774
7775 options_menu.select_uid(MENUID_OPTIONS_EPILEPSYPROT, epilepsyFlashReduction);
7776 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7777 options_menu.disable_uid(MENUID_OPTIONS_SHOWBOTTOMPIXELS, replay_is_replaying());
7778
7779 name_entry_mode_menu.select_only_index(NameEntryMode);
7780
7781 misc_menu.select_uid(MENUID_MISC_CONSOLE, console_enabled);
7782 misc_menu.select_uid(MENUID_MISC_CLEAR_CONSOLE_ON_LOAD, clearConsoleOnLoad);
7783
7784 bool nocheat = (replay_is_replaying() || !Playing
7785 || (!maxcheat && !zcheats.flags && !get_debug() && DEVLEVEL < 2 && !zqtesting_mode && !devpwd()));
7786 the_player_menu.disable_uid(MENUID_PLAYER_CHEAT, nocheat);
7787 refill_menu.disable_uid(MENUID_REFILL_ARROWS, !get_qr(qr_TRUEARROWS));
7788 cheat_menu.chop_index.reset();
7789 if(cheat < 4)
7790 cheat_menu.chop_index = cheat_menu.ind_at(MENUID_CHEAT_CHOP_L1+cheat);
7791 cheat_menu.select_uid(MENUID_CHEAT_INVULN, getClock());
7792 cheat_menu.select_uid(MENUID_CHEAT_NOCLIP, walk_through_walls);
7793 cheat_menu.select_uid(MENUID_CHEAT_IGNORESV, ignoreSideview);
7794 cheat_menu.select_uid(MENUID_CHEAT_GOFAST, gofast);
7795
7796 show_menu.select_uid(MENUID_SHOW_L0, show_layers[0]);
7797 show_menu.select_uid(MENUID_SHOW_L1, show_layers[1]);
7798 show_menu.select_uid(MENUID_SHOW_L2, show_layers[2]);
7799 show_menu.select_uid(MENUID_SHOW_L3, show_layers[3]);
7800 show_menu.select_uid(MENUID_SHOW_L4, show_layers[4]);
7801 show_menu.select_uid(MENUID_SHOW_L5, show_layers[5]);
7802 show_menu.select_uid(MENUID_SHOW_L6, show_layers[6]);
7803 show_menu.select_uid(MENUID_SHOW_OVER, show_layer_over);
7804 show_menu.select_uid(MENUID_SHOW_PUSH, show_layer_push);
7805 show_menu.select_uid(MENUID_SHOW_SPR, show_sprites);
7806 show_menu.select_uid(MENUID_SHOW_FFC, show_ffcs);
7807 show_menu.select_uid(MENUID_SHOW_SOLIDITY, show_walkflags);
7808 show_menu.select_uid(MENUID_SHOW_SCRIPTNAME, show_ff_scripts);
7809 show_menu.select_uid(MENUID_SHOW_HITBOX, show_hitboxes);
7810 show_menu.select_uid(MENUID_SHOW_EFFECT, show_effectflags);
7811
7812 settings_menu.select_uid(MENUID_SETTINGS_HEARTBEEP, heart_beep);
7813 settings_menu.select_uid(MENUID_SETTINGS_SAVEINDICATOR, use_save_indicator);
7814
7815 replay_menu.by_uid(MENUID_REPLAY_STOP)->text = fmt::format("Stop {}",
7816 replay_get_mode() == ReplayMode::Record ? "recording" : "replaying");
7817
7818 replay_menu.select_uid(MENUID_REPLAY_RECORDNEW, zc_get_config("zeldadx", "replay_new_saves", false));
7819 #ifdef HAS_CURL
7820 replay_menu.select_uid(MENUID_REPLAY_AUTOUPLOAD, replay_upload_auto_enabled());
7821 #endif
7822 replay_menu.disable_uid(MENUID_REPLAY_STOP, !replay_is_active());
7823 replay_menu.disable_uid(MENUID_REPLAY_SAVE, replay_get_mode() != ReplayMode::Record);
7824 replay_menu.select_uid(MENUID_REPLAY_SNAP_ALL, replay_is_snapshot_all_frames());
7825
7826 snapshot_format_menu.select_only_index(SnapshotFormat);
7827 bottom_8_pixels_menu.select_only_index(ShowBottomPixels);
7828 }
7829
7830 if(debug_enabled)
7831 settings_menu.select_uid(MENUID_SETTINGS_DEBUG, get_debug());
7832
7833 if(autopop)
7834 clear_keybuf();
7835 the_player_menu.run(true);
7836 if(autopop)
7837 {
7838 the_player_menu.pop_sub(0, &the_player_menu);
7839 the_player_menu.draw(screen, the_player_menu.hovered_ind());
7840 autopop = false;
7841 update_hw_screen();
7842 }
7843
7844 update_hw_screen();
7845
7846 auto mb = gui_mouse_b();
7847 if(XOR(mb, mouse_down))
7848 {
7849 if(!the_player_menu.has_mouse())
7850 if(mb)
7851 break;
7852 mouse_down = mb;
7853 }
7854
7855 if(input_idle(true) > after_time())
7856 // run Screeen Saver
7857 {
7858 // Screen saver enabled for now.
7859 clear_keybuf();
7860 Matrix(ss_speed, ss_density, 0);
7861 system_pal(true);
7862 sys_mouse();
7863 }
7864
7865 poll_keyboard();
7866 if(esc)
7867 {
7868 if(!key[KEY_ESC])
7869 esc = false;
7870 }
7871
7872 if(keypressed() && !CHECK_ALT) //System hotkeys
7873 {
7874 auto c = peekkey();
7875 bool eatkey = true;
7876 switch(c>>8)
7877 {
7878 //Spare keys used by the menu
7879 case KEY_UP:
7880 case KEY_DOWN:
7881 case KEY_LEFT:
7882 case KEY_RIGHT:
7883 eatkey = false;
7884 break;
7885 case KEY_F1:
7886 onThrottleFPS();
7887 break;
7888 case KEY_F2:
7889 onShowFPS();
7890 break;
7891 case KEY_F6:
7892 onTryQuitMenu();
7893 break;
7894 #ifndef ALLEGRO_MACOSX
7895 case KEY_F9:
7896 onReset();
7897 break;
7898 case KEY_F10:
7899 onExit();
7900 break;
7901 #else
7902 case KEY_F7:
7903 onReset();
7904 break;
7905 case KEY_F8:
7906 onExit();
7907 break;
7908 #endif
7909 case KEY_F12:
7910 onSnapshot();
7911 break;
7912 case KEY_TAB:
7913 onDebug();
7914 break;
7915 case KEY_ESC:
7916 if(!esc)
7917 running = false;
7918 break;
7919 }
7920 if(eatkey)
7921 readkey();
7922 }
7923 if(Quit || (GameFlags & GAMEFLAG_TRYQUIT))
7924 break;
7925 }
7926 while(running);
7927
7928 screen = oldscreen;
7929
7930 mouse_down=gui_mouse_b();
7931 MenuOpen = false;
7932 if(Quit)
7933 {
7934 kill_sfx();
7935 music_stop();
7936 update_hw_screen();
7937 }
7938 else
7939 {
7940 music_resume();
7941 resume_all_sfx();
7942
7943 if(rc)
7944 ringcolor(false);
7945 }
7946 exit_sys_pal();
7947
7948 eat_buttons();
7949
7950 rc=false;
7951 clear_keybuf();
7952
7953 zc_init_apply_cheat_delta();
7954 }
7955
7956 325 void fix_dialogs()
7957 {
7958 325 jwin_center_dialog(about_dlg);
7959 325 jwin_center_dialog(gamepad_dlg);
7960 325 jwin_center_dialog(credits_dlg);
7961 325 jwin_center_dialog(gamemode_dlg);
7962 325 jwin_center_dialog(getnum_dlg);
7963 325 jwin_center_dialog(goto_dlg);
7964 325 jwin_center_dialog(keyboard_control_dlg);
7965 325 jwin_center_dialog(midi_dlg);
7966 325 jwin_center_dialog(quest_dlg);
7967 325 jwin_center_dialog(scrsaver_dlg);
7968 325 jwin_center_dialog(sound_dlg);
7969 325 jwin_center_dialog(triforce_dlg);
7970 325 }
7971
7972 4341 INLINE int32_t mixvol(int32_t v1,int32_t v2)
7973 {
7974
3/4
✓ Branch 0 taken 4341 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4319 times.
✓ Branch 3 taken 22 times.
4341 return (zc_min(v1,255)*zc_min(v2,255)) >> 8;
7975 }
7976
7977 340 int32_t get_emusic_volume()
7978 {
7979 340 int32_t temp_volume = emusic_volume;
7980
3/4
✓ Branch 0 taken 340 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 294 times.
✓ Branch 3 taken 46 times.
340 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
7981 46 temp_volume = (emusic_volume * FFCore.usr_music_volume) / 10000 / 100;
7982
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 340 times.
340 if (!zcmusic)
7983 340 return temp_volume;
7984 return (temp_volume * zcmusic->fadevolume) / 10000;
7985 340 }
7986
7987 int32_t get_zcmusicpos()
7988 {
7989 int32_t debugtracething = zcmusic_get_curpos(zcmusic);
7990 return debugtracething;
7991 return 0;
7992 }
7993
7994 void set_zcmusicpos(int32_t position)
7995 {
7996 zcmusic_set_curpos(zcmusic, position);
7997 }
7998
7999 void set_zcmusicspeed(int32_t speed)
8000 {
8001 zcmusic_set_speed(zcmusic, speed);
8002 }
8003
8004 int32_t get_zcmusiclen()
8005 {
8006 return zcmusic_get_length(zcmusic);
8007 }
8008
8009 3 void set_zcmusicloop(double start, double end)
8010 {
8011 3 zcmusic_set_loop(zcmusic, start, end);
8012 3 }
8013
8014 64179 void jukebox(int32_t index,int32_t loop)
8015 {
8016
1/2
✓ Branch 0 taken 64179 times.
✗ Branch 1 not taken.
64179 if (is_headless())
8017 64179 return;
8018
8019 music_stop();
8020
8021 if(index<0) index=MAXMIDIS-1;
8022
8023 if(index>=MAXMIDIS) index=0;
8024
8025 music_stop();
8026
8027 // Allegro's DIGMID driver (the one normally used on on Linux) gets
8028 // stuck notes when a song stops. This fixes it.
8029 if(strcmp(midi_driver->name, "DIGMID")==0)
8030 zc_set_volume(0, 0);
8031
8032 zc_set_volume(-1, mixvol(tunes[index].volume, midi_volume >>1));
8033 zc_play_midi(tunes[index].data,loop);
8034
8035 if(tunes[index].start>0)
8036 zc_midi_seek(tunes[index].start);
8037
8038 midi_loop_start = tunes[index].loop_start;
8039 midi_loop_end = tunes[index].loop_end;
8040
8041 currmidi=index;
8042 master_volume(digi_volume, midi_volume);
8043 //midi_paused=false;
8044 64179 }
8045
8046 64179 void jukebox(int32_t index)
8047 {
8048
1/2
✓ Branch 0 taken 64179 times.
✗ Branch 1 not taken.
64179 if(index<0) index=MAXMIDIS-1;
8049
8050
1/2
✓ Branch 0 taken 64179 times.
✗ Branch 1 not taken.
64179 if(index>=MAXMIDIS) index=0;
8051
8052 // do nothing if it's already playing
8053
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 64179 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
64179 if(index==currmidi && midi_pos>=0)
8054 {
8055 return;
8056 }
8057
8058 64179 jukebox(index,tunes[index].loop);
8059 64179 }
8060
8061 111 void play_DmapMusic()
8062 {
8063
1/2
✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
111 if (is_headless())
8064 111 return;
8065
8066 static char tfile[2048];
8067 static int32_t ttrack=0;
8068 bool domidi=false;
8069
8070 int32_t fadeoutframes = 0;
8071 if (zcmusic != NULL)
8072 fadeoutframes = zcmusic->fadeoutframes;
8073
8074 if(DMaps[cur_dmap].tmusic[0]!=0)
8075 {
8076 if(zcmusic==NULL ||
8077 strcmp(zcmusic->filename,DMaps[cur_dmap].tmusic)!=0 ||
8078 (zcmusic->type==ZCMF_GME && zcmusic->track != DMaps[cur_dmap].tmusictrack))
8079 {
8080 if (DMaps[cur_dmap].tmusic_xfade_in > 0 || fadeoutframes > 0)
8081 {
8082 if (play_enh_music_crossfade(DMaps[cur_dmap].tmusic, qstpath, DMaps[cur_dmap].tmusictrack, get_emusic_volume(), DMaps[cur_dmap].tmusic_xfade_in, fadeoutframes))
8083 {
8084 if (zcmusic != NULL)
8085 {
8086 zcmusic->fadeoutframes = DMaps[cur_dmap].tmusic_xfade_out;
8087 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
8088 }
8089 }
8090 }
8091 else
8092 {
8093 if (zcmusic != NULL)
8094 {
8095 zcmusic_stop(zcmusic);
8096 zcmusic_unload_file(zcmusic);
8097 zcmusic = NULL;
8098 zcmixer->newtrack = NULL;
8099 }
8100
8101 zcmusic = zcmusic_load_for_quest(DMaps[cur_dmap].tmusic, qstpath).first;
8102 zcmixer->newtrack = zcmusic;
8103
8104 if (zcmusic != NULL)
8105 {
8106 zc_stop_midi();
8107 strcpy(tfile, DMaps[cur_dmap].tmusic);
8108 zcmusic_play(zcmusic, emusic_volume);
8109 int32_t temptracks = 0;
8110 temptracks = zcmusic_get_tracks(zcmusic);
8111 temptracks = (temptracks < 2) ? 1 : temptracks;
8112 ttrack = vbound(DMaps[cur_dmap].tmusictrack, 0, temptracks - 1);
8113 zcmusic_change_track(zcmusic, ttrack);
8114 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
8115 }
8116 else
8117 {
8118 tfile[0] = 0;
8119 domidi = true;
8120 }
8121 }
8122 }
8123 }
8124 else
8125 {
8126 if (DMaps[cur_dmap].midi == 0 && fadeoutframes > 0 && zcmusic != NULL && strcmp(zcmusic->filename, DMaps[cur_dmap].tmusic) != 0)
8127 {
8128 play_enh_music_crossfade(NULL, qstpath, DMaps[cur_dmap].tmusictrack, get_emusic_volume(), DMaps[cur_dmap].tmusic_xfade_in, fadeoutframes);
8129 }
8130 else
8131 {
8132 domidi = true;
8133 }
8134 }
8135
8136 if(domidi)
8137 {
8138 int32_t m=DMaps[cur_dmap].midi;
8139
8140 switch(m)
8141 {
8142 case 1:
8143 jukebox(ZC_MIDI_OVERWORLD);
8144 break;
8145
8146 case 2:
8147 jukebox(ZC_MIDI_DUNGEON);
8148 break;
8149
8150 case 3:
8151 jukebox(ZC_MIDI_LEVEL9);
8152 break;
8153
8154 default:
8155 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8156 jukebox(m+MIDIOFFSET_DMAP);
8157 else
8158 music_stop();
8159 }
8160 }
8161 111 }
8162
8163 37417 void playLevelMusic()
8164 {
8165
1/2
✓ Branch 0 taken 37417 times.
✗ Branch 1 not taken.
37417 if (is_headless())
8166 37417 return;
8167
8168 int32_t m=hero_scr->screen_midi;
8169
8170 switch(m)
8171 {
8172 case -2:
8173 music_stop();
8174 break;
8175
8176 case -1:
8177 play_DmapMusic();
8178 break;
8179
8180 case 1:
8181 jukebox(ZC_MIDI_OVERWORLD);
8182 break;
8183
8184 case 2:
8185 jukebox(ZC_MIDI_DUNGEON);
8186 break;
8187
8188 case 3:
8189 jukebox(ZC_MIDI_LEVEL9);
8190 break;
8191
8192 default:
8193 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8194 jukebox(m+MIDIOFFSET_MAPSCR);
8195 else
8196 music_stop();
8197 }
8198 37417 }
8199
8200 4341 void master_volume(int32_t dv,int32_t mv)
8201 {
8202
7/8
✓ Branch 0 taken 2008 times.
✓ Branch 1 taken 2333 times.
✓ Branch 2 taken 1967 times.
✓ Branch 3 taken 366 times.
✓ Branch 4 taken 2333 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1967 times.
✓ Branch 7 taken 366 times.
4341 if(dv>=0) digi_volume=zc_max(zc_min(dv,255),0);
8203
8204
7/8
✓ Branch 0 taken 2004 times.
✓ Branch 1 taken 2337 times.
✓ Branch 2 taken 2000 times.
✓ Branch 3 taken 337 times.
✓ Branch 4 taken 2337 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2000 times.
✓ Branch 7 taken 337 times.
4341 if(mv>=0) midi_volume=zc_max(zc_min(mv,255),0);
8205
8206
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 4341 times.
✓ Branch 2 taken 4341 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4341 times.
4341 int32_t i = zc_min(zc_max(currmidi,0),MAXMIDIS-1);
8207 4341 int32_t temp_vol = midi_volume;
8208
2/2
✓ Branch 0 taken 4016 times.
✓ Branch 1 taken 325 times.
4341 if (!get_qr(qr_OLD_SCRIPT_VOLUME))
8209 325 temp_vol = (midi_volume * FFCore.usr_music_volume) / 10000 / 100;
8210 4341 zc_set_volume(digi_volume,mixvol(tunes[i].volume, temp_vol));
8211 4341 }
8212
8213 // array of voices, one for each sfx sample in the data file
8214 // 0+ = voice #
8215 // -1 = voice not allocated
8216 325 void Z_init_sound()
8217 {
8218
2/2
✓ Branch 0 taken 83200 times.
✓ Branch 1 taken 325 times.
83525 for(int32_t i=0; i<WAV_COUNT; i++)
8219 83200 sfx_voice[i]=-1;
8220
8221 325 const char* midis[ZC_MIDI_COUNT] = {
8222 "assets/dungeon.mid",
8223 "assets/ending.mid",
8224 "assets/gameover.mid",
8225 "assets/level9.mid",
8226 "assets/overworld.mid",
8227 "assets/title.mid",
8228 "assets/triforce.mid",
8229 };
8230
2/2
✓ Branch 0 taken 2275 times.
✓ Branch 1 taken 325 times.
2600 for(int32_t i=0; i<ZC_MIDI_COUNT; i++)
8231 {
8232 2275 tunes[i].data = load_midi(midis[i]);
8233
1/2
✓ Branch 0 taken 2275 times.
✗ Branch 1 not taken.
2275 if (!tunes[i].data)
8234 Z_error_fatal("Missing required file %s\n", midis[i]);
8235 2275 }
8236
8237
2/2
✓ Branch 0 taken 81900 times.
✓ Branch 1 taken 325 times.
82225 for(int32_t j=0; j<MAXCUSTOMMIDIS; j++)
8238 81900 tunes[ZC_MIDI_COUNT+j].data=NULL;
8239
8240 325 master_volume(digi_volume,midi_volume);
8241 325 }
8242
8243 // returns number of voices currently allocated
8244 int32_t sfx_count()
8245 {
8246 int32_t c=0;
8247
8248 for(int32_t i=0; i<WAV_COUNT; i++)
8249 if(sfx_voice[i]!=-1)
8250 ++c;
8251
8252 return c;
8253 }
8254
8255 // clean up finished samples
8256 18990300 void sfx_cleanup()
8257 {
8258
2/2
✓ Branch 0 taken 4861516800 times.
✓ Branch 1 taken 18990300 times.
4880507100 for(int32_t i=0; i<WAV_COUNT; i++)
8259
3/4
✓ Branch 0 taken 1309291 times.
✓ Branch 1 taken 4860207509 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1309291 times.
4862826091 if(sfx_voice[i]!=-1 && voice_get_position(sfx_voice[i])<0)
8260 {
8261 1309291 deallocate_voice(sfx_voice[i]);
8262 1309291 sfx_voice[i]=-1;
8263 1309291 }
8264 18990300 }
8265
8266 1309469 SAMPLE* sfx_get_sample(int32_t index)
8267 {
8268 // check index
8269
2/4
✓ Branch 0 taken 1309469 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1309469 times.
1309469 if (index<=0 || index>=WAV_COUNT)
8270 return nullptr;
8271
8272
2/2
✓ Branch 0 taken 446247 times.
✓ Branch 1 taken 863222 times.
1309469 if (sfxdat)
8273 {
8274
1/2
✓ Branch 0 taken 446247 times.
✗ Branch 1 not taken.
446247 if (index<Z35)
8275 {
8276 446247 return (SAMPLE*)sfxdata[index].dat;
8277 }
8278 else
8279 {
8280 return (SAMPLE*)sfxdata[Z35].dat;
8281 }
8282 }
8283 else
8284 {
8285 863222 return &customsfxdata[index];
8286 }
8287
8288 return nullptr;
8289 1309469 }
8290
8291 // allocates a voice for the sample "wav_index" (index into zelda.dat)
8292 // if a voice is already allocated (and/or playing), then it just returns true
8293 // Returns true: voice is allocated
8294 // false: unsuccessful
8295 2063771 bool sfx_init(int32_t index)
8296 {
8297 // check index
8298
3/4
✓ Branch 0 taken 1467131 times.
✓ Branch 1 taken 596640 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1467131 times.
2063771 if(index<=0 || index>=WAV_COUNT)
8299 596640 return false;
8300
8301
2/2
✓ Branch 0 taken 157727 times.
✓ Branch 1 taken 1309404 times.
1467131 if (sfx_voice[index] == -1)
8302 {
8303 1309404 SAMPLE* sample = sfx_get_sample(index);
8304
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1309404 times.
1309404 if (!sample)
8305 return false;
8306
8307 1309404 sfx_voice[index] = allocate_voice(sample);
8308 1309404 }
8309
8310 1467131 return sfx_voice[index] != -1;
8311 2063771 }
8312
8313 int32_t sfx_get_default_freq(int32_t index)
8314 {
8315 if (sfxdat)
8316 {
8317 if (index < Z35)
8318 {
8319 return ((SAMPLE*)sfxdata[index].dat)->freq;
8320 }
8321 else
8322 {
8323 return ((SAMPLE*)sfxdata[Z35].dat)->freq;
8324 }
8325 }
8326 else
8327 {
8328 return customsfxdata[index].freq;
8329 }
8330 }
8331
8332 int32_t sfx_get_length(int32_t index)
8333 {
8334 if (sfxdat)
8335 {
8336 if (index < Z35)
8337 {
8338 return int32_t(((SAMPLE*)sfxdata[index].dat)->len);
8339 }
8340 else
8341 {
8342 return int32_t(((SAMPLE*)sfxdata[Z35].dat)->len);
8343 }
8344 }
8345 else
8346 {
8347 return int32_t(customsfxdata[index].len);
8348 }
8349 }
8350
8351 // plays an sfx sample
8352 2063771 void sfx(int32_t index,int32_t pan,bool loop, bool restart, zfix vol_perc, int32_t freq)
8353 {
8354
2/2
✓ Branch 0 taken 1467131 times.
✓ Branch 1 taken 596640 times.
2063771 if(!sfx_init(index))
8355 596640 return;
8356
1/2
✓ Branch 0 taken 1467131 times.
✗ Branch 1 not taken.
1467131 if (!is_headless())
8357 {
8358 voice_set_playmode(sfx_voice[index], loop ? PLAYMODE_LOOP : PLAYMODE_PLAY);
8359 voice_set_pan(sfx_voice[index], pan);
8360
8361 // Only used by ZScript currently
8362 if (freq <= -1)
8363 {
8364 freq = sfx_get_default_freq(index);
8365 }
8366 voice_set_frequency(sfx_voice[index], freq);
8367
8368 // Only used by ZScript currently
8369 int32_t temp_volume = ((sfx_volume * vol_perc) / 100).getFloor();
8370 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
8371 temp_volume = (temp_volume * FFCore.usr_sfx_volume) / 10000 / 100;
8372 voice_set_volume(sfx_voice[index], temp_volume);
8373
8374 int32_t pos = voice_get_position(sfx_voice[index]);
8375
8376 if (restart) voice_set_position(sfx_voice[index], 0);
8377
8378 if (pos <= 0)
8379 voice_start(sfx_voice[index]);
8380 }
8381
8382
3/4
✓ Branch 0 taken 925203 times.
✓ Branch 1 taken 541928 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 925203 times.
1467131 if (restart && replay_is_debug())
8383 {
8384 // TODO(replays): get rid of this bandaid next time replays are mass-updated.
8385 925203 const char* sfx_name = sfx_string[index];
8386
2/2
✓ Branch 0 taken 913417 times.
✓ Branch 1 taken 11786 times.
925203 if (strcmp(sfx_name, "Hero is hit") == 0)
8387 11786 sfx_name = "Player is hit";
8388
2/2
✓ Branch 0 taken 913290 times.
✓ Branch 1 taken 127 times.
913417 else if (strcmp(sfx_name, "Hero dies") == 0)
8389 127 sfx_name = "Player dies";
8390
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 925203 times.
925203 replay_step_comment(fmt::format("sfx {}", sfx_name));
8391 925203 }
8392 2063771 }
8393
8394 // true if sfx is allocated
8395 234209 bool sfx_allocated(int32_t index)
8396 {
8397
3/4
✓ Branch 0 taken 33547 times.
✓ Branch 1 taken 200662 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 33547 times.
234209 return (index>0 && index<WAV_COUNT && sfx_voice[index]!=-1);
8398 }
8399
8400 // start it (in loop mode) if it's not already playing,
8401 // otherwise adjust it to play in loop mode -DD
8402 125813 void cont_sfx(int32_t index)
8403 {
8404
1/2
✓ Branch 0 taken 125813 times.
✗ Branch 1 not taken.
125813 if (is_headless())
8405 125813 return;
8406
8407 if(!sfx_init(index))
8408 {
8409 return;
8410 }
8411
8412 if(voice_get_position(sfx_voice[index])<=0)
8413 {
8414 voice_set_position(sfx_voice[index],0);
8415 voice_set_playmode(sfx_voice[index],PLAYMODE_LOOP);
8416 voice_set_volume(sfx_voice[index], sfx_volume);
8417 voice_start(sfx_voice[index]);
8418 }
8419 else
8420 {
8421 adjust_sfx(index, 128, true);
8422 }
8423 125813 }
8424
8425 // adjust parameters while playing
8426 5380 void adjust_sfx(int32_t index,int32_t pan,bool loop)
8427 {
8428
4/6
✓ Branch 0 taken 4831 times.
✓ Branch 1 taken 549 times.
✓ Branch 2 taken 4831 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4831 times.
5380 if(index<=0 || index>=WAV_COUNT || sfx_voice[index]==-1)
8429 5380 return;
8430
8431 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
8432 voice_set_pan(sfx_voice[index],pan);
8433 5380 }
8434
8435 // pauses a voice
8436 3365 void pause_sfx(int32_t index)
8437 {
8438
3/6
✓ Branch 0 taken 3365 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3365 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3365 times.
3365 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8439 voice_stop(sfx_voice[index]);
8440 3365 }
8441
8442 // resumes a voice
8443 1428 void resume_sfx(int32_t index)
8444 {
8445
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1428 times.
1428 if (is_headless())
8446 1428 return;
8447
8448 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8449 voice_start(sfx_voice[index]);
8450 1428 }
8451
8452 // pauses all active voices
8453 1129 void pause_all_sfx()
8454 {
8455
2/2
✓ Branch 0 taken 289024 times.
✓ Branch 1 taken 1129 times.
290153 for(int32_t i=0; i<WAV_COUNT; i++)
8456
2/2
✓ Branch 0 taken 289022 times.
✓ Branch 1 taken 2 times.
289026 if(sfx_voice[i]!=-1)
8457 2 voice_stop(sfx_voice[i]);
8458 1129 }
8459
8460 // resumes all paused voices
8461 1070 void resume_all_sfx()
8462 {
8463
2/2
✓ Branch 0 taken 273920 times.
✓ Branch 1 taken 1070 times.
274990 for(int32_t i=0; i<WAV_COUNT; i++)
8464
1/2
✓ Branch 0 taken 273920 times.
✗ Branch 1 not taken.
273920 if(sfx_voice[i]!=-1)
8465 voice_start(sfx_voice[i]);
8466 1070 }
8467
8468 // stops an sfx and deallocates the voice
8469 15143066 void stop_sfx(int32_t index)
8470 {
8471
3/4
✓ Branch 0 taken 14889336 times.
✓ Branch 1 taken 253730 times.
✓ Branch 2 taken 14889336 times.
✗ Branch 3 not taken.
15143066 if(index<=0 || index>=WAV_COUNT)
8472 253730 return;
8473
8474
2/2
✓ Branch 0 taken 55 times.
✓ Branch 1 taken 14889281 times.
14889336 if(sfx_voice[index]!=-1)
8475 {
8476 55 deallocate_voice(sfx_voice[index]);
8477 55 sfx_voice[index]=-1;
8478 55 }
8479 15143066 }
8480
8481 // Stops SFX played by Hero's item of the given family
8482 163371 void stop_item_sfx(int32_t family)
8483 {
8484 163371 int32_t id=current_item_id(family);
8485
8486
2/2
✓ Branch 0 taken 162269 times.
✓ Branch 1 taken 1102 times.
163371 if(id<0)
8487 162269 return;
8488
8489 1102 stop_sfx(itemsbuf[id].usesound);
8490 163371 }
8491
8492 9760 void kill_sfx()
8493 {
8494
2/2
✓ Branch 0 taken 2498560 times.
✓ Branch 1 taken 9760 times.
2508320 for(int32_t i=0; i<WAV_COUNT; i++)
8495
2/2
✓ Branch 0 taken 2498502 times.
✓ Branch 1 taken 58 times.
2498618 if(sfx_voice[i]!=-1)
8496 {
8497 58 deallocate_voice(sfx_voice[i]);
8498 58 sfx_voice[i]=-1;
8499 58 }
8500 9760 }
8501
8502 // TODO: when far out of bounds, sounds should dampen. currently we only pan.
8503 1255460 int32_t pan(int32_t x)
8504 {
8505
1/5
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1255460 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1255460 switch(pan_style)
8506 {
8507 // MONO
8508 case 0:
8509 return 128;
8510
8511 // 1/2
8512 case 1:
8513 1255460 x -= viewport.x;
8514 1255460 return vbound((x>>1)+68,0,255);
8515
8516 // 3/4
8517 case 2:
8518 x -= viewport.x;
8519 return vbound(((x*3)>>2)+36,0,255);
8520
8521 // FULL
8522 case 3:
8523 default:
8524 x -= viewport.x;
8525 return vbound(x,0,255);
8526 }
8527 1255460 }
8528
8529 52033631 bool joybtn(int32_t b)
8530 {
8531
1/2
✓ Branch 0 taken 52033631 times.
✗ Branch 1 not taken.
52033631 if(b == 0)
8532 return false;
8533
1/2
✓ Branch 0 taken 52033631 times.
✗ Branch 1 not taken.
52033631 if (b-1 >= joy[joystick_index].num_buttons)
8534 52033631 return false;
8535
8536 return joy[joystick_index].button[b-1].b !=0;
8537 52033631 }
8538
8539 bool joystick(int32_t s)
8540 {
8541 if(s < 0)
8542 return false;
8543 if (s >= joy[joystick_index].num_sticks)
8544 return false;
8545
8546 for (int i = 0; i < joy[joystick_index].stick[s].num_axis; i++)
8547 {
8548 if (joy[joystick_index].stick[s].axis[i].d1 || joy[joystick_index].stick[s].axis[i].d2)
8549 return true;
8550 }
8551 return false;
8552 }
8553
8554 const char* joybtn_name(int32_t b)
8555 {
8556 if (b <= 0 || b > joy[joystick_index].num_buttons)
8557 return "";
8558
8559 return joy[joystick_index].button[b-1].name;
8560 }
8561
8562 const char* joystick_name(int32_t s)
8563 {
8564 if (s < 0 || s >= joy[joystick_index].num_sticks)
8565 return "";
8566
8567 return joy[joystick_index].stick[s].name;
8568 }
8569
8570 int32_t button_pressed()
8571 {
8572 if (joystick_index >= MAX_JOYSTICKS)
8573 return 0;
8574
8575 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8576 {
8577 if(joybtn(i))
8578 return i;
8579 }
8580
8581 return 0;
8582 }
8583
8584 int32_t next_press_key();
8585
8586 int32_t next_joy_input(bool buttons)
8587 {
8588 clear_keybuf();
8589
8590 //first, we need to wait until they're pressing no buttons
8591 for(;;)
8592 {
8593 if(keypressed())
8594 {
8595 switch(readkey()>>8)
8596 {
8597 case KEY_ESC:
8598 return -1;
8599
8600 case KEY_SPACE:
8601 return 0;
8602 }
8603 }
8604
8605 poll_joystick();
8606 bool done = true;
8607
8608 if (buttons)
8609 {
8610 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8611 {
8612 if(joybtn(i)) done = false;
8613 }
8614 }
8615 else
8616 {
8617 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8618 {
8619 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8620 return -2;
8621 }
8622 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8623 {
8624 if(joystick(i)) done = false;
8625 }
8626 }
8627
8628 if(done) break;
8629 rest(1);
8630 }
8631
8632 //now, we need to wait for them to press any button
8633 for(;;)
8634 {
8635 if(keypressed())
8636 {
8637 switch(readkey()>>8)
8638 {
8639 case KEY_ESC:
8640 return -1;
8641
8642 case KEY_SPACE:
8643 return 0;
8644 }
8645 }
8646
8647 poll_joystick();
8648
8649 if (buttons)
8650 {
8651 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8652 {
8653 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8654 return -2;
8655 }
8656 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8657 {
8658 if(joybtn(i))
8659 return i;
8660 }
8661 }
8662 else
8663 {
8664 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8665 {
8666 if(joystick(i))
8667 return i;
8668 }
8669 }
8670 rest(1);
8671 }
8672 }
8673
8674 12808921 static bool rButton(bool &btn, bool &flag, bool rawbtn)
8675 {
8676
2/2
✓ Branch 0 taken 12725183 times.
✓ Branch 1 taken 83738 times.
12808921 bool ret = btn && !flag;
8677 12808921 flag = rawbtn;
8678
8679 12808921 return ret;
8680 }
8681 387393614 static bool rButton(bool &btn, bool &flag)
8682 {
8683
2/2
✓ Branch 0 taken 372892244 times.
✓ Branch 1 taken 14501370 times.
387393614 bool ret = btn && !flag;
8684 387393614 flag = btn;
8685
8686 387393614 return ret;
8687 }
8688 4658238 static bool rButtonPeek(bool btn, bool flag)
8689 {
8690
2/2
✓ Branch 0 taken 4309146 times.
✓ Branch 1 taken 349092 times.
4658238 if(!btn)
8691 {
8692 4309146 return false;
8693 }
8694
2/2
✓ Branch 0 taken 33878 times.
✓ Branch 1 taken 315214 times.
349092 else if(!flag)
8695 {
8696 33878 return true;
8697 }
8698
8699 315214 return false;
8700 4658238 }
8701
8702 // Updated only by keyboard/gamepad.
8703 // If in replay mode, this is set directly by the replay system.
8704 // This should never be read from directly - use control_state instead.
8705 bool raw_control_state[ZC_CONTROL_STATES];
8706
8707 // Every call to load_control_state (pretty much every frame) resets this to be equal to raw_control_state.
8708 // This state can drift from raw_control_state if button states are "eaten" or overriden by a script. But that only
8709 // lasts until the next call to load_control_state.
8710 bool control_state[ZC_CONTROL_STATES];
8711 bool disable_control[ZC_CONTROL_STATES];
8712 bool drunk_toggle_state[11];
8713 bool disabledKeys[127];
8714 bool KeyInput[127];
8715 bool KeyPress[127];
8716
8717 bool key_current_frame[127];
8718 bool key_previous_frame[127];
8719
8720 static bool key_system[127];
8721 static bool key_system_previous[127];
8722 static bool key_system_press[127];
8723
8724 bool button_press[ZC_CONTROL_STATES];
8725 bool button_hold[ZC_CONTROL_STATES];
8726
8727 #define STICK_1_X joy[joystick_index].stick[js_stick_1_x_stick].axis[js_stick_1_x_axis]
8728 #define STICK_1_Y joy[joystick_index].stick[js_stick_1_y_stick].axis[js_stick_1_y_axis]
8729 #define STICK_2_X joy[joystick_index].stick[js_stick_2_x_stick].axis[js_stick_2_x_axis]
8730 #define STICK_2_Y joy[joystick_index].stick[js_stick_2_y_stick].axis[js_stick_2_y_axis]
8731 #define STICK_PRECISION 56 //define your own sensitivity
8732
8733 16252324 void load_control_state()
8734 {
8735 16252324 load_control_called_this_frame = true;
8736
8737
2/2
✓ Branch 0 taken 13049262 times.
✓ Branch 1 taken 3203062 times.
16252324 if (replay_version_check(8, 11))
8738 {
8739
2/2
✓ Branch 0 taken 57655116 times.
✓ Branch 1 taken 3203062 times.
60858178 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8740 57655116 down_control_states[i] = raw_control_state[i];
8741 3203062 }
8742
8743
2/2
✓ Branch 0 taken 16252303 times.
✓ Branch 1 taken 21 times.
16252324 if (!replay_is_replaying())
8744 {
8745
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[0]=zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset < -STICK_PRECISION : joybtn(DUbtn));
8746
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[1]=zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn));
8747
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[2]=zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn));
8748
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[3]=zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn));
8749
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[4]=zc_getrawkey(Akey, true)||joybtn(Abtn);
8750
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[5]=zc_getrawkey(Bkey, true)||joybtn(Bbtn);
8751
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[6]=zc_getrawkey(Skey, true)||joybtn(Sbtn);
8752
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[7]=zc_getrawkey(Lkey, true)||joybtn(Lbtn);
8753
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[8]=zc_getrawkey(Rkey, true)||joybtn(Rbtn);
8754
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[9]=zc_getrawkey(Pkey, true)||joybtn(Pbtn);
8755
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[10]=zc_getrawkey(Exkey1, true)||joybtn(Exbtn1);
8756
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[11]=zc_getrawkey(Exkey2, true)||joybtn(Exbtn2);
8757
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[12]=zc_getrawkey(Exkey3, true)||joybtn(Exbtn3);
8758
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[13]=zc_getrawkey(Exkey4, true)||joybtn(Exbtn4);
8759
8760
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 if(num_joysticks != 0)
8761 {
8762 raw_control_state[14] = STICK_2_Y.pos - js_stick_2_y_offset < -STICK_PRECISION;
8763 raw_control_state[15] = STICK_2_Y.pos - js_stick_2_y_offset > STICK_PRECISION;
8764 raw_control_state[16] = STICK_2_X.pos - js_stick_2_x_offset < -STICK_PRECISION;
8765 raw_control_state[17] = STICK_2_X.pos - js_stick_2_x_offset > STICK_PRECISION;
8766 }
8767 else
8768 {
8769 21 raw_control_state[14] = false;
8770 21 raw_control_state[15] = false;
8771 21 raw_control_state[16] = false;
8772 21 raw_control_state[17] = false;
8773 }
8774 21 }
8775
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 16252319 times.
16252324 if (replay_is_active())
8776 {
8777
2/2
✓ Branch 0 taken 1194597 times.
✓ Branch 1 taken 15057722 times.
16252319 if (replay_get_version() < 3)
8778 1194597 replay_poll();
8779
4/4
✓ Branch 0 taken 15057701 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 13296326 times.
✓ Branch 3 taken 1761375 times.
15057722 else if (replay_is_replaying() && replay_get_version() < 6)
8780 1761375 replay_peek_input();
8781
4/4
✓ Branch 0 taken 13296326 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 10093264 times.
✓ Branch 3 taken 3203062 times.
13296347 else if (replay_is_replaying() && replay_version_check(8, 11))
8782 3203062 replay_peek_input();
8783
2/2
✓ Branch 0 taken 14912377 times.
✓ Branch 1 taken 1339942 times.
16252319 if (replay_get_version() == 8)
8784 1339942 update_keys();
8785 16252319 }
8786
8787 // Some test replay files were made before a serious input bug was fixed, so instead
8788 // of re-doing them or tossing them out, just check for that zplay version.
8789
3/4
✓ Branch 0 taken 16252314 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 121900 times.
✓ Branch 3 taken 16130414 times.
16252324 bool botched_input = replay_is_active() && replay_get_version() != 1 && replay_get_version() < 8;
8790
2/2
✓ Branch 0 taken 292541652 times.
✓ Branch 1 taken 16252314 times.
308793966 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8791 {
8792 292541652 control_state[i] = raw_control_state[i];
8793
4/4
✓ Branch 0 taken 52716150 times.
✓ Branch 1 taken 239825502 times.
✓ Branch 2 taken 2596831 times.
✓ Branch 3 taken 50119319 times.
292541652 if (botched_input && !control_state[i])
8794 50119319 down_control_states[i] = false;
8795 292541652 }
8796 16252314 bool did_bad_cutscene_btn = false;
8797
2/2
✓ Branch 0 taken 16252314 times.
✓ Branch 1 taken 292541652 times.
308793966 for(int q = 0; q < 18; ++q)
8798
4/4
✓ Branch 0 taken 13926486 times.
✓ Branch 1 taken 278615166 times.
✓ Branch 2 taken 13924775 times.
✓ Branch 3 taken 1711 times.
292543363 if(control_state[q] && !active_cutscene.can_button(q))
8799 {
8800 1711 control_state[q] = false;
8801 1711 did_bad_cutscene_btn = true;
8802 1711 }
8803
2/2
✓ Branch 0 taken 16251047 times.
✓ Branch 1 taken 1267 times.
16252314 if(did_bad_cutscene_btn)
8804 1267 active_cutscene.error();
8805
8806 16252314 button_press[0]=rButton(control_state[0],button_hold[0]);
8807 16252314 button_press[1]=rButton(control_state[1],button_hold[1]);
8808 16252314 button_press[2]=rButton(control_state[2],button_hold[2]);
8809 16252314 button_press[3]=rButton(control_state[3],button_hold[3]);
8810 16252314 button_press[4]=rButton(control_state[4],button_hold[4]);
8811 16252314 button_press[5]=rButton(control_state[5],button_hold[5]);
8812 16252314 button_press[6]=rButton(control_state[6],button_hold[6]);
8813 16252314 button_press[7]=rButton(control_state[7],button_hold[7]);
8814 16252314 button_press[8]=rButton(control_state[8],button_hold[8]);
8815 16252314 button_press[9]=rButton(control_state[9],button_hold[9]);
8816 16252314 button_press[10]=rButton(control_state[10],button_hold[10]);
8817 16252314 button_press[11]=rButton(control_state[11],button_hold[11]);
8818 16252314 button_press[12]=rButton(control_state[12],button_hold[12]);
8819 16252314 button_press[13]=rButton(control_state[13],button_hold[13]);
8820 16252314 button_press[14]=rButton(control_state[14],button_hold[14]);
8821 16252314 button_press[15]=rButton(control_state[15],button_hold[15]);
8822 16252314 button_press[16]=rButton(control_state[16],button_hold[16]);
8823 16252314 button_press[17]=rButton(control_state[17],button_hold[17]);
8824 16252314 }
8825
8826 // Returns true if any game key is pressed. This is needed because keypressed()
8827 // doesn't detect modifier keys and control_state[] can be modified by scripts.
8828 81309778 bool zc_key_pressed()
8829 //may also need to use zc_getrawkey
8830 {
8831
7/10
✓ Branch 0 taken 65612940 times.
✓ Branch 1 taken 15696838 times.
✓ Branch 2 taken 15696838 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15696838 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12826280 times.
✓ Branch 7 taken 12826280 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 5121027 times.
86430805 if((zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset< -STICK_PRECISION : joybtn(DUbtn))) ||
8832
4/6
✓ Branch 0 taken 12826280 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12826280 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9746747 times.
✓ Branch 5 taken 9746747 times.
12826280 (zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn))) ||
8833
4/6
✓ Branch 0 taken 9746747 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9746747 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6449866 times.
✓ Branch 5 taken 6449866 times.
9746747 (zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn))) ||
8834
4/6
✓ Branch 0 taken 6449866 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6449866 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5539796 times.
✓ Branch 5 taken 5539796 times.
6449866 (zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn))) ||
8835
1/2
✓ Branch 0 taken 5539796 times.
✗ Branch 1 not taken.
5539796 (zc_getrawkey(Akey, true)||joybtn(Abtn)) ||
8836
3/4
✓ Branch 0 taken 5346407 times.
✓ Branch 1 taken 193389 times.
✓ Branch 2 taken 5346407 times.
✗ Branch 3 not taken.
5539796 (zc_getrawkey(Bkey, true)||joybtn(Bbtn)) ||
8837
3/4
✓ Branch 0 taken 5198257 times.
✓ Branch 1 taken 148150 times.
✓ Branch 2 taken 5198257 times.
✗ Branch 3 not taken.
5346407 (zc_getrawkey(Skey, true)||joybtn(Sbtn)) ||
8838
3/4
✓ Branch 0 taken 5174844 times.
✓ Branch 1 taken 23413 times.
✓ Branch 2 taken 5174844 times.
✗ Branch 3 not taken.
5198257 (zc_getrawkey(Lkey, true)||joybtn(Lbtn)) ||
8839
3/4
✓ Branch 0 taken 5147744 times.
✓ Branch 1 taken 27100 times.
✓ Branch 2 taken 5147744 times.
✗ Branch 3 not taken.
5174844 (zc_getrawkey(Rkey, true)||joybtn(Rbtn)) ||
8840
3/4
✓ Branch 0 taken 5140189 times.
✓ Branch 1 taken 7555 times.
✓ Branch 2 taken 5140189 times.
✗ Branch 3 not taken.
5147744 (zc_getrawkey(Pkey, true)||joybtn(Pbtn)) ||
8841
3/4
✓ Branch 0 taken 5122950 times.
✓ Branch 1 taken 17239 times.
✓ Branch 2 taken 5122950 times.
✗ Branch 3 not taken.
5140189 (zc_getrawkey(Exkey1, true)||joybtn(Exbtn1)) ||
8842
3/4
✓ Branch 0 taken 5121121 times.
✓ Branch 1 taken 1829 times.
✓ Branch 2 taken 5121121 times.
✗ Branch 3 not taken.
5122950 (zc_getrawkey(Exkey2, true)||joybtn(Exbtn2)) ||
8843
3/4
✓ Branch 0 taken 5121086 times.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 5121086 times.
✗ Branch 3 not taken.
5121121 (zc_getrawkey(Exkey3, true)||joybtn(Exbtn3)) ||
8844
2/2
✓ Branch 0 taken 5121027 times.
✓ Branch 1 taken 59 times.
5121086 (zc_getrawkey(Exkey4, true)||joybtn(Exbtn4))) // Skipping joystick axes
8845 145314129 return true;
8846
8847 5121027 return false;
8848 19209276 }
8849
8850 311573478 bool getInput(int32_t btn, int input_flags)
8851 {
8852
3/4
✓ Branch 0 taken 277688672 times.
✓ Branch 1 taken 33884806 times.
✓ Branch 2 taken 277688672 times.
✗ Branch 3 not taken.
311573478 if((input_flags & INPUT_HERO_ACTION) && Hero.no_control())
8853 return false;
8854
8855 311573478 bool press = input_flags & INPUT_PRESS;
8856 311573478 bool drunk = input_flags & INPUT_DRUNK;
8857 311573478 bool ignoreDisable = input_flags & INPUT_IGNORE_DISABLE;
8858 311573478 bool eatEntirely = input_flags & INPUT_EAT_ENTIRELY;
8859 311573478 bool peek = input_flags & INPUT_PEEK;
8860
8861 311573478 bool ret = false, drunkstate = false, rawret = false;;
8862 311573478 bool* flag = &down_control_states[btn];
8863
2/7
✓ Branch 0 taken 292344950 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 19228528 times.
311573478 switch(btn)
8864 {
8865 case btnF12:
8866 ret = zc_getkey(KEY_F12, ignoreDisable);
8867 rawret = zc_getrawkey(KEY_F12, ignoreDisable);
8868 eatEntirely = false;
8869 break;
8870 case btnF11:
8871 ret = zc_getkey(KEY_F11, ignoreDisable);
8872 rawret = zc_getrawkey(KEY_F11, ignoreDisable);
8873 eatEntirely = false;
8874 break;
8875 case btnF5:
8876 ret = zc_getkey(KEY_F5, ignoreDisable);
8877 rawret = zc_getrawkey(KEY_F5, ignoreDisable);
8878 eatEntirely = false;
8879 break;
8880 case btnQ:
8881 ret = zc_getkey(KEY_Q, ignoreDisable);
8882 rawret = zc_getrawkey(KEY_Q, ignoreDisable);
8883 eatEntirely = false;
8884 break;
8885 case btnI:
8886 ret = zc_getkey(KEY_I, ignoreDisable);
8887 rawret = zc_getrawkey(KEY_I, ignoreDisable);
8888 eatEntirely = false;
8889 break;
8890 case btnM:
8891
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19228528 times.
19228528 if(FFCore.kb_typing_mode) return false;
8892 19228528 rawret = ret = zc_getrawkey(KEY_ESC, ignoreDisable);
8893 19228528 eatEntirely = false;
8894 19228528 break;
8895 default: //control_state[] index
8896
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 292344950 times.
292344950 if(FFCore.kb_typing_mode) return false;
8897
6/6
✓ Branch 0 taken 290948033 times.
✓ Branch 1 taken 1396917 times.
✓ Branch 2 taken 29318747 times.
✓ Branch 3 taken 261629286 times.
✓ Branch 4 taken 29315774 times.
✓ Branch 5 taken 2973 times.
292344950 if(!ignoreDisable && get_qr(qr_FIXDRUNKINPUTS) && disable_control[btn]) drunk = false;
8898
2/2
✓ Branch 0 taken 17508974 times.
✓ Branch 1 taken 274833003 times.
292341977 else if(btn<11) drunkstate = drunk_toggle_state[btn];
8899
4/4
✓ Branch 0 taken 259382364 times.
✓ Branch 1 taken 32962586 times.
✓ Branch 2 taken 7270 times.
✓ Branch 3 taken 32955316 times.
325307536 ret = control_state[btn] && (ignoreDisable || !disable_control[btn]);
8900 292344950 rawret = raw_control_state[btn];
8901 292344950 }
8902
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 311573478 times.
311573478 assert(flag);
8903
2/2
✓ Branch 0 taken 199254357 times.
✓ Branch 1 taken 112319121 times.
311573478 if(press)
8904 {
8905
2/2
✓ Branch 0 taken 4658238 times.
✓ Branch 1 taken 107660883 times.
112319121 if(peek)
8906 4658238 ret = rButtonPeek(ret, *flag);
8907
2/2
✓ Branch 0 taken 94851962 times.
✓ Branch 1 taken 12808921 times.
107660883 else if(get_qr(qr_BROKEN_INPUT_DOWN_STATE)) ret = rButton(ret, *flag);
8908 12808921 else ret = rButton(ret, *flag, rawret);
8909 112319121 }
8910
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 311573478 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
311573478 if(eatEntirely && ret) control_state[btn] = false;
8911
4/4
✓ Branch 0 taken 232198020 times.
✓ Branch 1 taken 79375458 times.
✓ Branch 2 taken 232197939 times.
✓ Branch 3 taken 81 times.
311573478 if(drunk && drunkstate) ret = !ret;
8912 311573478 return ret;
8913 311573478 }
8914
8915 15547271 byte getIntBtnInput(byte intbtn, int input_flags)
8916 {
8917 15547271 byte ret = 0;
8918
2/2
✓ Branch 0 taken 11103254 times.
✓ Branch 1 taken 4444017 times.
15547271 if(intbtn & INT_BTN_A) ret |= getInput(btnA, input_flags) ? INT_BTN_A : 0;
8919
2/2
✓ Branch 0 taken 15330321 times.
✓ Branch 1 taken 216950 times.
15547271 if(intbtn & INT_BTN_B) ret |= getInput(btnB, input_flags) ? INT_BTN_B : 0;
8920
2/2
✓ Branch 0 taken 15331639 times.
✓ Branch 1 taken 215632 times.
15547271 if(intbtn & INT_BTN_L) ret |= getInput(btnL, input_flags) ? INT_BTN_L : 0;
8921
2/2
✓ Branch 0 taken 15331639 times.
✓ Branch 1 taken 215632 times.
15547271 if(intbtn & INT_BTN_R) ret |= getInput(btnR, input_flags) ? INT_BTN_R : 0;
8922
2/2
✓ Branch 0 taken 15331639 times.
✓ Branch 1 taken 215632 times.
15547271 if(intbtn & INT_BTN_EX1) ret |= getInput(btnEx1, input_flags) ? INT_BTN_EX1 : 0;
8923
2/2
✓ Branch 0 taken 15331639 times.
✓ Branch 1 taken 215632 times.
15547271 if(intbtn & INT_BTN_EX2) ret |= getInput(btnEx2, input_flags) ? INT_BTN_EX2 : 0;
8924
2/2
✓ Branch 0 taken 15331639 times.
✓ Branch 1 taken 215632 times.
15547271 if(intbtn & INT_BTN_EX3) ret |= getInput(btnEx3, input_flags) ? INT_BTN_EX3 : 0;
8925
2/2
✓ Branch 0 taken 15331524 times.
✓ Branch 1 taken 215747 times.
15547271 if(intbtn & INT_BTN_EX4) ret |= getInput(btnEx4, input_flags) ? INT_BTN_EX4 : 0;
8926 15547271 return ret; //No early return, to make sure all button presses are eaten that should be! -Em
8927 }
8928
8929 7513 byte checkIntBtnVal(byte intbtn, byte vals)
8930 {
8931 7513 return intbtn&vals;
8932 }
8933
8934 219071 bool Up()
8935 {
8936 219071 return getInput(btnUp);
8937 }
8938 219070 bool Down()
8939 {
8940 219070 return getInput(btnDown);
8941 }
8942 219070 bool Left()
8943 {
8944 219070 return getInput(btnLeft);
8945 }
8946 219070 bool Right()
8947 {
8948 219070 return getInput(btnRight);
8949 }
8950 553062 bool cAbtn()
8951 {
8952 553062 return getInput(btnA);
8953 }
8954 3375106 bool cBbtn()
8955 {
8956 3375106 return getInput(btnB);
8957 }
8958 bool cSbtn()
8959 {
8960 return getInput(btnS);
8961 }
8962 218976 bool cLbtn()
8963 {
8964 218976 return getInput(btnL);
8965 }
8966 218976 bool cRbtn()
8967 {
8968 218976 return getInput(btnR);
8969 }
8970 bool cPbtn()
8971 {
8972 return getInput(btnP);
8973 }
8974 bool cEx1btn()
8975 {
8976 return getInput(btnEx1);
8977 }
8978 bool cEx2btn()
8979 {
8980 return getInput(btnEx2);
8981 }
8982 bool cEx3btn()
8983 {
8984 return getInput(btnEx3);
8985 }
8986 bool cEx4btn()
8987 {
8988 return getInput(btnEx4);
8989 }
8990 bool AxisUp()
8991 {
8992 return getInput(btnAxisUp);
8993 }
8994 bool AxisDown()
8995 {
8996 return getInput(btnAxisDown);
8997 }
8998 bool AxisLeft()
8999 {
9000 return getInput(btnAxisLeft);
9001 }
9002 bool AxisRight()
9003 {
9004 return getInput(btnAxisRight);
9005 }
9006
9007 bool cMbtn()
9008 {
9009 return getInput(btnM);
9010 }
9011 bool cF12()
9012 {
9013 return getInput(btnF12);
9014 }
9015 bool cF11()
9016 {
9017 return getInput(btnF11);
9018 }
9019 bool cF5()
9020 {
9021 return getInput(btnF5);
9022 }
9023 bool cQ()
9024 {
9025 return getInput(btnQ);
9026 }
9027 bool cI()
9028 {
9029 return getInput(btnI);
9030 }
9031
9032 219470 bool rUp()
9033 {
9034 219470 return getInput(btnUp, INPUT_PRESS);
9035 }
9036 219218 bool rDown()
9037 {
9038 219218 return getInput(btnDown, INPUT_PRESS);
9039 }
9040 218967 bool rLeft()
9041 {
9042 218967 return getInput(btnLeft, INPUT_PRESS);
9043 }
9044 218111 bool rRight()
9045 {
9046 218111 return getInput(btnRight, INPUT_PRESS);
9047 }
9048 4835 bool rAbtn()
9049 {
9050 4835 return getInput(btnA, INPUT_PRESS);
9051 }
9052 bool rBbtn()
9053 {
9054 return getInput(btnB, INPUT_PRESS);
9055 }
9056 218348 bool rSbtn()
9057 {
9058 218348 return getInput(btnS, INPUT_PRESS);
9059 }
9060 19209276 bool rMbtn()
9061 {
9062 19209276 return getInput(btnM, INPUT_PRESS);
9063 }
9064 186046 bool rLbtn()
9065 {
9066 186046 return getInput(btnL, INPUT_PRESS);
9067 }
9068 186041 bool rRbtn()
9069 {
9070 186041 return getInput(btnR, INPUT_PRESS);
9071 }
9072 218976 bool rPbtn()
9073 {
9074 218976 return getInput(btnP, INPUT_PRESS);
9075 }
9076 bool rEx1btn()
9077 {
9078 return getInput(btnEx1, INPUT_PRESS);
9079 }
9080 bool rEx2btn()
9081 {
9082 return getInput(btnEx2, INPUT_PRESS);
9083 }
9084 186037 bool rEx3btn()
9085 {
9086 186037 return getInput(btnEx3, INPUT_PRESS);
9087 }
9088 186037 bool rEx4btn()
9089 {
9090 186037 return getInput(btnEx4, INPUT_PRESS);
9091 }
9092 bool rAxisUp()
9093 {
9094 return getInput(btnAxisUp, INPUT_PRESS);
9095 }
9096 bool rAxisDown()
9097 {
9098 return getInput(btnAxisDown, INPUT_PRESS);
9099 }
9100 bool rAxisLeft()
9101 {
9102 return getInput(btnAxisLeft, INPUT_PRESS);
9103 }
9104 bool rAxisRight()
9105 {
9106 return getInput(btnAxisRight, INPUT_PRESS);
9107 }
9108
9109 bool rF11()
9110 {
9111 return getInput(btnF11, INPUT_PRESS);
9112 }
9113 bool rQ()
9114 {
9115 return getInput(btnQ, INPUT_PRESS);
9116 }
9117 bool rI()
9118 {
9119 return getInput(btnI, INPUT_PRESS);
9120 }
9121
9122 bool DrunkUp()
9123 {
9124 return getInput(btnUp, INPUT_DRUNK);
9125 }
9126 bool DrunkDown()
9127 {
9128 return getInput(btnDown, INPUT_DRUNK);
9129 }
9130 bool DrunkLeft()
9131 {
9132 return getInput(btnLeft, INPUT_DRUNK);
9133 }
9134 bool DrunkRight()
9135 {
9136 return getInput(btnRight, INPUT_DRUNK);
9137 }
9138 bool DrunkcAbtn()
9139 {
9140 return getInput(btnA, INPUT_DRUNK);
9141 }
9142 bool DrunkcBbtn()
9143 {
9144 return getInput(btnB, INPUT_DRUNK);
9145 }
9146 bool DrunkcEx1btn()
9147 {
9148 return getInput(btnEx1, INPUT_DRUNK);
9149 }
9150 bool DrunkcEx2btn()
9151 {
9152 return getInput(btnEx2, INPUT_DRUNK);
9153 }
9154 bool DrunkcSbtn()
9155 {
9156 return getInput(btnS, INPUT_DRUNK);
9157 }
9158 bool DrunkcMbtn()
9159 {
9160 return getInput(btnM, INPUT_DRUNK);
9161 }
9162 bool DrunkcLbtn()
9163 {
9164 return getInput(btnL, INPUT_DRUNK);
9165 }
9166 bool DrunkcRbtn()
9167 {
9168 return getInput(btnR, INPUT_DRUNK);
9169 }
9170 bool DrunkcPbtn()
9171 {
9172 return getInput(btnP, INPUT_DRUNK);
9173 }
9174
9175 bool DrunkrUp()
9176 {
9177 return getInput(btnUp, INPUT_PRESS | INPUT_DRUNK);
9178 }
9179 bool DrunkrDown()
9180 {
9181 return getInput(btnDown, INPUT_PRESS | INPUT_DRUNK);
9182 }
9183 bool DrunkrLeft()
9184 {
9185 return getInput(btnLeft, INPUT_PRESS | INPUT_DRUNK);
9186 }
9187 bool DrunkrRight()
9188 {
9189 return getInput(btnRight, INPUT_PRESS | INPUT_DRUNK);
9190 }
9191 bool DrunkrAbtn()
9192 {
9193 return getInput(btnA, INPUT_PRESS | INPUT_DRUNK);
9194 }
9195 bool DrunkrBbtn()
9196 {
9197 return getInput(btnB, INPUT_PRESS | INPUT_DRUNK);
9198 }
9199 bool DrunkrEx1btn()
9200 {
9201 return getInput(btnEx1, INPUT_PRESS | INPUT_DRUNK);
9202 }
9203 bool DrunkrEx2btn()
9204 {
9205 return getInput(btnEx2, INPUT_PRESS | INPUT_DRUNK);
9206 }
9207 bool DrunkrEx3btn()
9208 {
9209 return getInput(btnEx3, INPUT_PRESS | INPUT_DRUNK);
9210 }
9211 bool DrunkrEx4btn()
9212 {
9213 return getInput(btnEx4, INPUT_PRESS | INPUT_DRUNK);
9214 }
9215 bool DrunkrSbtn()
9216 {
9217 return getInput(btnS, INPUT_PRESS | INPUT_DRUNK);
9218 }
9219 bool DrunkrMbtn()
9220 {
9221 return getInput(btnM, INPUT_PRESS | INPUT_DRUNK);
9222 }
9223 bool DrunkrLbtn()
9224 {
9225 return getInput(btnL, INPUT_PRESS | INPUT_DRUNK);
9226 }
9227 bool DrunkrRbtn()
9228 {
9229 return getInput(btnR, INPUT_PRESS | INPUT_DRUNK);
9230 }
9231 bool DrunkrPbtn()
9232 {
9233 return getInput(btnP, INPUT_PRESS | INPUT_DRUNK);
9234 }
9235
9236 19252 void eat_buttons()
9237 {
9238 19252 getInput(btnA, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9239 19252 getInput(btnB, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9240 19252 getInput(btnS, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9241 19252 getInput(btnM, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9242 19252 getInput(btnL, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9243 19252 getInput(btnR, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9244 19252 getInput(btnP, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9245 19252 getInput(btnEx1, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9246 19252 getInput(btnEx2, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9247 19252 getInput(btnEx3, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9248 19252 getInput(btnEx4, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9249 19252 }
9250
9251 // Is true for the _first frame_ of a key press.
9252 // But! it is possible that a script manually sets the value of KeyPress,
9253 // in which case it will be restored to the "true" value based on `key_current_frame`
9254 // and `key_previous_frame` on the next frame.
9255 59 bool zc_readkey(int32_t k, bool ignoreDisable)
9256 {
9257
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
59 if(ignoreDisable) return KeyPress[k];
9258
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
59 switch(k)
9259 {
9260 case KEY_F7:
9261 case KEY_F8:
9262 case KEY_F9:
9263 return KeyPress[k];
9264
9265 default:
9266
2/2
✓ Branch 0 taken 47 times.
✓ Branch 1 taken 12 times.
59 return KeyPress[k] && !disabledKeys[k];
9267 }
9268 59 }
9269
9270 // Is true for _every frame_ a key is held down.
9271 // But! it is possible that a script manually sets the value of KeyInput,
9272 // in which case it will be restored to the "true" value based on `key_current_frame`
9273 // on the next frame.
9274 bool zc_getkey(int32_t k, bool ignoreDisable)
9275 {
9276 if(ignoreDisable) return KeyInput[k];
9277 switch(k)
9278 {
9279 case KEY_F7:
9280 case KEY_F8:
9281 case KEY_F9:
9282 return KeyInput[k];
9283
9284 default:
9285 return KeyInput[k] && !disabledKeys[k];
9286 }
9287 }
9288
9289 // Reads (and then clears) the current frame key state directly.
9290 // Scripts can also modify `key_current_frame`.
9291 954 bool zc_readrawkey(int32_t k, bool ignoreDisable)
9292 {
9293
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 950 times.
954 if(zc_getrawkey(k, ignoreDisable))
9294 {
9295 4 _key[k]=key[k]=key_current_frame[k]=0;
9296 4 return true;
9297 }
9298 950 _key[k]=key[k]=key_current_frame[k]=0;
9299 950 return false;
9300 954 }
9301
9302 // Reads the current frame key state directly.
9303 // Scripts can also modify `key_current_frame`.
9304 130071177 bool zc_getrawkey(int32_t k, bool ignoreDisable)
9305 {
9306
2/2
✓ Branch 0 taken 110861783 times.
✓ Branch 1 taken 19209394 times.
130071177 if(ignoreDisable) return key_current_frame[k];
9307
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19209394 times.
19209394 switch(k)
9308 {
9309 case KEY_F7:
9310 case KEY_F8:
9311 case KEY_F9:
9312 return key_current_frame[k];
9313
9314 default:
9315
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19209394 times.
19209394 return key_current_frame[k] && !disabledKeys[k];
9316 }
9317 130071177 }
9318
9319 // Only used for a handful of keys, like tilde and Function keys.
9320 // This state is never read within the game.
9321 // It exists so that all keyboard input still functions during replay,
9322 // without inadvertently doing things like toggling throttling if the player
9323 // presses ~
9324 bool zc_get_system_key(int32_t k)
9325 {
9326 return key_system[k];
9327 }
9328
9329 // True for the _first_ frame of a key press.
9330 172883484 bool zc_read_system_key(int32_t k)
9331 {
9332 172883484 return key_system_press[k];
9333 }
9334
9335 2439578052 bool is_system_key(int32_t k)
9336 {
9337
2/2
✓ Branch 0 taken 2266694568 times.
✓ Branch 1 taken 172883484 times.
2439578052 switch (k)
9338 {
9339 case KEY_BACKQUOTE:
9340 case KEY_CLOSEBRACE:
9341 case KEY_END:
9342 case KEY_HOME:
9343 case KEY_OPENBRACE:
9344 case KEY_PGDN:
9345 case KEY_PGUP:
9346 case KEY_TAB:
9347 case KEY_TILDE:
9348 172883484 return true;
9349 }
9350 2266694568 return is_Fkey(k);
9351 2439578052 }
9352
9353 19209276 void update_system_keys()
9354 {
9355
2/2
✓ Branch 0 taken 2439578052 times.
✓ Branch 1 taken 19209276 times.
2458787328 for (int32_t q = 0; q < 127; ++q)
9356 {
9357
2/2
✓ Branch 0 taken 403394796 times.
✓ Branch 1 taken 2036183256 times.
2439578052 if (!is_system_key(q))
9358 2036183256 continue;
9359
9360 403394796 key_system[q] = key[q];
9361
1/2
✓ Branch 0 taken 403394796 times.
✗ Branch 1 not taken.
403394796 key_system_press[q] = key_system[q] && !key_system_previous[q];
9362 403394796 key_system_previous[q] = key_system[q];
9363 403394796 }
9364 19209276 }
9365
9366 20549218 void update_keys()
9367 {
9368
2/2
✓ Branch 0 taken 2609750686 times.
✓ Branch 1 taken 20549218 times.
2630299904 for (int32_t q = 0; q < 127; ++q)
9369 {
9370 // When replaying, replay.cpp takes care of updating `key_current_frame`.
9371
2/2
✓ Branch 0 taken 2609737986 times.
✓ Branch 1 taken 12700 times.
2609750686 if (!replay_is_replaying())
9372 12700 key_current_frame[q] = key[q];
9373
9374
2/2
✓ Branch 0 taken 2589669053 times.
✓ Branch 1 taken 20081633 times.
2609750686 KeyPress[q] = key_current_frame[q] && !key_previous_frame[q];
9375 2609750686 KeyInput[q] = key_current_frame[q];
9376 2609750686 key_previous_frame[q] = key_current_frame[q];
9377 2609750686 }
9378 20549218 }
9379
9380